Regular Expression and Useage
Regular Expression and Useage
am 30.10.2007 18:54:43 von inderpaul_s
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. 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.
\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b
Many thanks in advance.
Victor
Re: Regular Expression and Useage
am 30.10.2007 20:31:38 von kingskippus
On Oct 30, 1:54 pm, "inderpau...@yahoo.com"
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. 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.
>
> \b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b
>
> Many thanks in advance.
>
> Victor
Please take a look at the answers to the exact same question you
posted less than 24 hours ago in the thread titled, "Regex Help."
--TV
Re: Regular Expression and Useage
am 30.10.2007 20:41:27 von Paul Lalli
On Oct 30, 1:54 pm, "inderpau...@yahoo.com"
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
Re: Regular Expression and Useage
am 30.10.2007 21:10:23 von inderpaul_s
On Oct 30, 11:31 am, TonyV wrote:
> On Oct 30, 1:54 pm, "inderpau...@yahoo.com"
> 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. 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.
>
> > \b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b
>
> > Many thanks in advance.
>
> > Victor
>
> Please take a look at the answers to the exact same question you
> posted less than 24 hours ago in the thread titled, "Regex Help."
>
> --TV
Sorry to ask but if you can send me the URL to the post I would be
happy to read that. For some reason I have been unable to find my own
post either through my profile or just plain searching the NG where I
posted. Hence the reason for my posting again. I'm not sure what the
issue is.
Re: Regular Expression and Useage
am 30.10.2007 21:12:51 von inderpaul_s
On Oct 30, 11:41 am, Paul Lalli wrote:
> On Oct 30, 1:54 pm, "inderpau...@yahoo.com"
> 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.
Re: Regular Expression and Useage
am 30.10.2007 21:24:58 von inderpaul_s
On Oct 30, 11:41 am, Paul Lalli wrote:
> On Oct 30, 1:54 pm, "inderpau...@yahoo.com"
> 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
Paul does it matter if I'm using these Perl Regular Expressions in C+
+ ? Is the implementation of this RegEx engine not the same uner any
platform ? Its not working in C++.
Re: Regular Expression and Useage
am 30.10.2007 21:39:43 von Jim Gibson
In article <1193775898.489424.50020@q5g2000prf.googlegroups.com>,
<"inderpaul_s@yahoo.com"> wrote:
> On Oct 30, 11:41 am, Paul Lalli wrote:
> > On Oct 30, 1:54 pm, "inderpau...@yahoo.com"
> > wrote:
> >
> > > I'm somewhat new to regular expression and want to know how to extract
> > > any strings which match an IP address.
> >
[good advice from Paul snipped]
>
> Paul does it matter if I'm using these Perl Regular Expressions in C+
> + ? Is the implementation of this RegEx engine not the same uner any
> platform ? Its not working in C++.
>
Yes, it matters. Since this group is about the Perl language, everybody
who read your post assumed you were talking about the Perl regular
expression engine. Other regex engines will have their own
implementation and their own rules. You cannot assume that what is true
for Perl is also true for the regex engine you are using. You need to
read the documentation for the implementation you are using.
--
Jim Gibson
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Re: Regular Expression and Useage
am 30.10.2007 22:02:49 von inderpaul_s
On Oct 30, 12:39 pm, Jim Gibson wrote:
> In article <1193775898.489424.50...@q5g2000prf.googlegroups.com>,
>
> <"inderpau...@yahoo.com"> wrote:
> > On Oct 30, 11:41 am, Paul Lalli wrote:
> > > On Oct 30, 1:54 pm, "inderpau...@yahoo.com"
> > > wrote:
>
> > > > I'm somewhat new to regular expression and want to know how to extract
> > > > any strings which match an IP address.
>
> [good advice from Paul snipped]
>
>
>
> > Paul does it matter if I'm using these Perl Regular Expressions in C+
> > + ? Is the implementation of this RegEx engine not the same uner any
> > platform ? Its not working in C++.
>
> Yes, it matters. Since this group is about the Perl language, everybody
> who read your post assumed you were talking about the Perl regular
> expression engine. Other regex engines will have their own
> implementation and their own rules. You cannot assume that what is true
> for Perl is also true for the regex engine you are using. You need to
> read the documentation for the implementation you are using.
>
> --
> Jim Gibson
>
> Posted Via Usenet.com Premium Usenet Newsgroup Services
> ----------------------------------------------------------
> ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
> ----------------------------------------------------------
> http://www.usenet.com
My apologies everyone I am newbie to programming including Perl.