Showing results for 
Search instead for 
Did you mean: 

Match Regular Expression with 2 expressions

Go to solution

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):

  1.        NNNNLNNNNNNN
  2.        LNNLLNNNNNNN

Is it possible to create an expression to do one of two things?

  1. Search for either pattern with an OR statement
  2. Search for the first four characters with an OR statement & the last eight with an AND; ie. (NNNN | LNNL) && LNNNNNNN

Examples of valid match:

  1. 0123A9876543
  2. A12AB9876543
0 Kudos
Message 1 of 8

For the first part, try this:


To do it the second way:


Message 2 of 8

Not an answer but I've found using the following website to be very helpful when working on any regular expressions.

Matt J | National Instruments | CLA
Message 3 of 8

Your second regex that doesn't work will work if you remove the spaces right before and after the pipe character "|".



0 Kudos
Message 4 of 8
Accepted by topic author SgtPeprLHCB


Message 5 of 8

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.

0 Kudos
Message 6 of 8

You can still replace [0-9] with \d to make it shorter!



Message 7 of 8

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...


Message 8 of 8