03-08-2012 01:27 PM
Here is a basic XML parser that will work regardless of whether the tag has attributes or not. It will also return the list of attributes. The offset is used if you need to retrieve multiple items with the same tag.
03-08-2012 01:54 PM
@IziShaw wrote:
[...] I was trying something like \(Ndx\s[0-9]+\) and so on. I was getting the whole match
Do you understand the regular expression? I looked for a literal '(', then used submatches to get the data name and value. I frequently use this type of construct: "[^ ]* ". It looks for "a string of anything that's not a [something], followed by a [something]. In this case, it's looking for the opening "(" and making a submatch of everything up to the first space, then a submatch of everything up to the ")".
\(([^ ]*) ([^\)]*)\)
09-19-2012 10:26 PM
I was wondering if someone could help me with this "simple" regex problem.
We have a template naming convention as follows:
<code>_<version_number>_<name>.mtt eg. IDS1_v1_IDS+PSU_Procedure ver2.mtt
and the <code> segment must follow these rules:
1) Must have only two or three captial letters followed by
2) only one or two digits
Now I'm trying to create an expression that will confirm if this is occuring as follows
ie. look for 2 or 3 capital lettes [A-Z]{2,3} followed by 1 or 2 numbers [0-9]{1,2}
Which works for most situations, but as you can see not the one above, or something like CS5+
Can anyone help?
Chris
09-20-2012 12:05 AM
You're almost there! If you're trying to validate only the first prefix in the protocol, try the regex [A-Z]{2,3}[0-9]{1,2}$ -- the dollar sign anchors to the end of the string, and will not validate your two test inputs of CS300 or CS5+
09-20-2012 01:07 AM
It's OK I figured it out - I wasn't anchoring the beginning and end of the string
^[A-Z]{2,3}[0-9]{1,2}$
Chris
09-20-2012 02:06 AM
Thanks Jack for your answer - now I was wondering if there was a more elegant solution for the <name>.mtt portion than what I've done below?
Basically I want to parse anything in the <name> portion (underscores, periods, hyphens etc), but filter off just the .mtt characters.
eg. IDS1_v1_IDS+PSU_Procedure.mtt should give me IDS+PSU_Procedure
Can you go two for two Jack?
09-20-2012 02:56 AM
@ChrisReed wrote:
Thanks Jack for your answer - now I was wondering if there was a more elegant solution for the <name>.mtt portion than what I've done below?
Basically I want to parse anything in the <name> portion (underscores, periods, hyphens etc), but filter off just the .mtt characters.
eg. IDS1_v1_IDS+PSU_Procedure.mtt should give me IDS+PSU_Procedure
How about something like the regex ^([A-Z]{2,3}[0-9]{1,2})_(.+?)_(.+?)\.mtt$ and dropping "Scan from String" in favor of "Match Regular Expression". Don't forget to escape the period before the file extension \.mtt rather than just .mtt (which would mean, any char followed by mtt) - and also check out laziness that the ? introduces to the .+ "match one or more characters" pattern. (And the parentheses in LabVIEW are treated as submatches)
09-20-2012 04:15 AM
Oh so that's how you can get submatches with the Match Regular Expression VI
I threw all manner of rubbish template file names at your Regex and they all passed with flying colours - thanks
Chris
09-20-2012 07:23 AM - edited 09-20-2012 07:49 AM
I thought this board was intended to post examples of regex, and not to answer questions. Like the Excel board. I'm confused.
09-20-2012 08:08 AM
But then regular expressions are pure gibberish to me anyway, so it's not that big a of surprise. I get a headache every time I look at them or have to use them.