Jump to content

Recommended Posts

Posted (edited)

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
Posted

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"

Posted

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?

Posted

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

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

"be smart, drink your wine"

Posted (edited)

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

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...