Re: Regular Expression and Useage



On Oct 30, 11:41 am, Paul Lalli <mri...@xxxxxxxxx> wrote:
On Oct 30, 1:54 pm, "inderpau...@xxxxxxxxx" <inderpau...@xxxxxxxxx>
wrote:

I'm somewhat new to regular expression and want to know how to extract
any strings which match an IP address.

I found this on the net and wanted to know if this is the most
efficient (easiest/shortest) way to write the expression or
pattern to match.

Shouldn't you first be concerned about whether it's the most *correct*
before you worry about efficiency?

Also in the discovered solution why do they use the \b word
boundary switch since the characters are of a numeric type ?
I'm not sure about this.

A "word" character in Perl is any letter, number, or underscore.
Therefore, the \b prevents other numbers from being next to the IP
address. That is, it prevents 921128.0.0.123423 from matching. Of
course, it also prevents HOME128.0.0.1, which may or may not be what
you want.

\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b

It could be shortened to:
\b(?:\d{1,3}\.){3}\d{1,3}\b

Or you could/should use Regexp::Common from CPAN and just write:
/\b$RE{net}{IPv4}\b/

Which not only is more easily readable, but also prevents such false-
matches as 318.99.183.999. That is, it takes care of checking the
individual components' sizes for you.

Paul Lalli


Thanks Paul for the help. I tested the above solution the one I had
found and discovered that it does not work for me. I'm not sure why.

.



Relevant Pages

  • Re: Regular Expression and Useage
    ... pattern to match. ... boundary switch since the characters are of a numeric type? ... Paul Lalli ... Paul does it matter if I'm using these Perl Regular Expressions in C+ ...
    (comp.lang.perl.misc)
  • Re: WILDCARD: output all a* by searching a text file
    ... where * denotes a string of characters. ... When you want to write a program that search a pattern such as /a./ ... int main{ ... int main(int argc,const char** argv){ ...
    (comp.programming)
  • Re: Expert script (.bat) writers help needed (strip double-quote from string)
    ... Sets or returns the regular expression pattern being searched for. ... Always a RegExp object variable. ... May include any of the regular expression characters defined in the table in the Settings section. ...
    (microsoft.public.windowsxp.help_and_support)
  • Re: First round of descriptive/external exercises
    ... I don't see coming up with that sort of omni pattern by ... The Mason/Della lie thing has ALWAYS been about ... >stuff, because you're nearly always dealing with two or more characters, ... lie to fit her action. ...
    (rec.arts.sf.composition)
  • Re: RegEx: How to ignore the number of whitespaces?
    ... matching character sequences in strings. ... what are the limitations of the "arbitrary Unicode characters?" ... Exactly one of them must be found in the string, ... Certain subsequences of a pattern may be marked as optional. ...
    (microsoft.public.dotnet.framework)