Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #85195

Re: re.findall help

Date 2015-02-04 14:07 +1100
From Cameron Simpson <cs@zip.com.au>
Subject Re: re.findall help
References <11aa8a80-bfdc-4e6f-a922-cb64c4da0466@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.18453.1423019250.18130.python-list@python.org> (permalink)

Show all headers | View raw


On 03Feb2015 18:52, w3tmb1@gmail.com <w3tmb1@gmail.com> wrote:
>I am trying to extract the following from a data stream using find all what 
>would be the best way to capture the ip address only from the following text " 
>ip=192.168.1.36 port=4992 " I also want to make sure the program can handle 
>the ip that is as high as 255.255.255.255

I would not be using re.findall.

If you have strings such as the one you describe I would:

  - call .split() on the string to break it up on whitespace

  - select the strings starting with "ip="

  - split those strings on "=" and grab the stuff after the "="

  - if you want to validate the address: split it on '.', check that there are 4 components, call "int()" on each component to check that is an int, and then check the value of the int as being in the range 0..255 inclusive

Write some code doing the above, test it, and if stuck, return with:

  - the code

  - example input for which it does not work

  - an explaination of what it does do (including an output transcript showing the badness if possible)

  - an explaination of how the output is wrong, and what it should look like

Cheers,
Cameron Simpson <cs@zip.com.au>

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

re.findall help w3tmb1@gmail.com - 2015-02-03 18:52 -0800
  Re: re.findall help Cameron Simpson <cs@zip.com.au> - 2015-02-04 14:07 +1100
  Re: re.findall help Jugurtha Hadjar <jugurtha.hadjar@gmail.com> - 2015-02-04 14:35 +0100

csiph-web