Jump to content

Need help with regular expressions


Recommended Posts

Posted (edited)

Hello,

I'm trying to parse a version number of format 00.00.00.00 from some telnet traffic.

I get several lines of output from telnet when I send it a "version" command.

I'm using the match pattern function on the returned lines and among the regex-es I used are:

\d\d\.d\d\.d\d\.d\d\

m/([0-9]{2}.){3}[0-9]{2}/

and variants of these, as well as other regex-es.

I always get the version string plus the several lines afterward. as though the regex is being ignored.

Is there anything about how LV implements regex that quirky , or some issue I should know about?

Thanks!

J

Edited by jbabb
Posted

Hello,

I'm trying to parse a version number of format 00.00.00.00 from some telnet traffic.

I get several lines of output from telnet when I send it a "version" command.

I'm using the match pattern function on the returned lines and among the regex-es I used are:

\d\d\.d\d\.d\d\.d\d\

m/[0-9].{3}[0-9]/

and variants of these, as well as other regex-es.

I always get the version string plus the several lines afterward. as though the regex is being ignored.

Is there anything about how LV implements regex that quirky , or some issue I should know about?

Thanks!

J

Can you post more of the surrounding data? Also, are you simply trying to extract the version string out of the data?

Posted
Is there anything about how LV implements regex that quirky , or some issue I should know about?

I don't have LabVIEW at home so I can't test anything, but there's a comment in the help for Match Regular Expression that says:

The Match Regular Expression function gives you more options for matching strings but performs more slowly than the Match Pattern function.

I've had trouble using Match Pattern and fixed the problems by using Match Regular Expression.

I'm also thinking that \d\d\.d\d\.d\d\.d\d\ should be \d\d\.\d\d\.\d\d\.\d\d instead and that m/[0-9].{3}[0-9]/ might be better as ([0-9]\.[0-9]){3}.

I sure wish I could test this in LabVIEW...

Posted

The following regular expression will extract a version string from the text: [0-9]{2}\.[0-9]{2}\.[0-9]{2}\.[0-9]{2}

Here is a condensed version of the regular expression: ([0-9]{2}\.){3}[0-9]{2}

It is not clear from your code exactly what you are trying to accomplish though.

Screen shot of the code.

post-4959-125418114614_thumb.png

Posted

Hello,

Thanks very much to all for your suggestions . And yes Mark Y., I am trying to just extract the version string. I will start trying them out now.

J

Posted

Hello and THANKS to all .

That was it! I used the regular expression match and one of the patterns posted as well, and it worked the FIRST time.

Thanks!

Jeff

Posted

As jcarmody pointed out, you didn't properly escape your regex - "d" is a the digit group and needs to be proceeded with a backslash. Likewise, a period is a single wildcard character and must be escaped if you're actually looking for a literal period.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.