Jump to content
Sign in to follow this  
crzftx

StringRegExp()

Recommended Posts

crzftx

I ran "StringRegExp($string,"(\d{1,3}[.]){3}\d{1,3}[:]\d{5}",1)" on a long string with a bunch of different IPs scattered about it. I thought it would return all of the IPs of the form 000.000.000.000:00000 where the first five 000 could be 1-3 digits long, thereby capturing all of the IPs. The return is oddly a 1-index array with only "83." in it. Any help on the Regular Expression would be great!

Edited by crzftx

Share this post


Link to post
Share on other sites
Siao

Flag for global matching is 3, not 1.

You have first octet and the dot in a group, therefore it's the only thing that gets captured.


"be smart, drink your wine"

Share this post


Link to post
Share on other sites
crzftx

Well that did help. Thanks Siao. So... is the group always the only thing that is captured? To capture the IP would I have to do something like

Global $array = StringRegExp($string,"(\d{1,3}[.]\d{1,3}[.]\d{1,3}[.]\d{1,3}[:]\d{5})",3)
How would I go about using a group without having the group alone returned?

Share this post


Link to post
Share on other sites
Siao

How would I go about using a group without having the group alone returned?

Non-capturing group - (?: ... )

"be smart, drink your wine"

Share this post


Link to post
Share on other sites
crzftx

Thanks a lot! Now I can capture lists of IPs quickly.

StringRegExp($string,"(?:\d{1,3}[.]){3}\d{1,3}[:]\d{5}",3)

Edited by crzftx

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×