08-03-2015 04:16 PM
I am faced with an issue of finding the IP address in a string containing other string like items... such as letters and numbers and... (ok, I'm just messing around). Anyways, the string could look like the following "10.0.0.1 stuff, stuff, stuff" or "stuff, stuff, stuff, 10.0.0.1 stuff, stuff." The bright side is that periods/dot is only used for IP addresses while comma is used for everything else. So I was thinking... well ok, I could just use a while loop and match pattern to solve this one. But then I thought.... "that's so primitive. Surely, there's a better way to do this." Sooooooo, is there a better way to do this? I'm using LabVIEW 2011 just an fyi.
Solved! Go to Solution.
08-03-2015 04:28 PM - edited 08-03-2015 04:29 PM
What's wrong with primitive? Sounds like a good way to solve it.
08-03-2015 04:37 PM - edited 08-03-2015 04:38 PM
Use "Match Regular Expression" with one of the expressions listed here: https://www.safaribooksonline.com/library/view/regular-expressions-cookbook/9780596802837/ch07s16.ht...
EDIT: more specifically, you want to use one of the expressions for matching an IP address from within a larger body of text, of course.
08-03-2015 04:46 PM
Hey man, we all want to move along just a little quicker (poor wheel reference)
Seems like the following match would be ideal to search for,
^([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$
However, it would appear this syntax does not agree with LabVIEW. You sure about this?
08-03-2015 04:51 PM
As I noted too late in my edit, you want to use the version for finding an IP address in a larger block of text, rather than the first version on that page. the ^ and $ are beginning- and end-of-line patterns, and you're not looking for an IP address on a line by itself.
Other than that, is there some way in which that syntax doesn't agree with LabVIEW? Works for me once I remove the ^ and $.
08-03-2015 05:04 PM - edited 08-03-2015 05:04 PM
Ok, I hate being Mr. Spoonfed, but might you be willing to post a jpg of your VI so that I may compare to mine own. I'm using match pattern but receiving no matches. Does your text contain more than just IP addresses?
08-03-2015 05:15 PM
On second thought, here's mine
.
08-03-2015 05:30 PM
The function you need to use is Match Regular Expression, not Match Pattern.
08-03-2015 05:32 PM
Yep, thank you sir!