02-21-2018 09:58 AM
I'm trying to create an expression that will search a string for 1 of 2 patterns using the Match Regular Expression function in LabVIEW 2016. I want to pick out 12 characters from a string of some length in a line.
The patterns are as follows, where 'L' is a letter (A-Z) & 'N' is a number (0-9):
Is it possible to create an expression to do one of two things?
Examples of valid match:
Solved! Go to Solution.
02-21-2018 02:49 PM - edited 02-21-2018 02:51 PM
For the first part, try this:
[0-9]{4,4}[A-Z][0-9]{7,7}|[A-Z][0-9]{2,2}[A-Z]{2,2}[0-9]{7,7}
To do it the second way:
([0-9]{4,4}|[A-Z][0-9]{2,2}[A-Z])[A-Z][0-9]{7,7}
02-21-2018 03:12 PM
Not an answer but I've found using the following website to be very helpful when working on any regular expressions.
02-21-2018 03:23 PM
02-21-2018 03:31 PM
([0-9]{4}[A-Z]|[A-Z][0-9]{2}[A-Z]{2})[0-9]{7}
02-22-2018 08:45 AM - edited 02-22-2018 08:46 AM
Thank you all! All great answers and all work. I went with the last answer since it was the shortest.
Kudos to Matt J. for the great webpage.
02-22-2018 08:48 AM
02-26-2018 04:28 AM
Besides the \d:
45 characters: ([0-9]{4}[A-Z]|[A-Z][0-9]{2}[A-Z]{2})[0-9]{7} ->
36 characters: (\d{4}[A-Z]|[A-Z]\d{2}[A-Z]{2})\d{7}
the last [A-Z] in the first capturing group can be brought outside the OR:
32 characters: (\d{4}|[A-Z]\d\d[A-Z])[A-Z]\d{7}
Obviously, less characters should not be a goal, but I think it's a bit clearer as well...
LabVIEW Programming ((make LV more popular, read this)