Q:

Using a Regular expression to extract required data

I am trying to modify my current regular expression to be more exclusive.
This is what I have so far:
RE.Pattern = "(L\d{1}-\w{2}-\w{4,7}-DATA-\d{3,4})"

What this does is extracts the following examples of strings from a load of junk data. FYI these strings are NOT static, the number values etc will change between cells.
L2-R2-TEST-DATA-4724
L1-SR-TESTING-DATA-472
L1-R2-WORKING-DATA-472

The above strings are what I want, however as well as this it will also extract the data below:
L1-R2-WRONGON-DATA-4725
L2-SR-RUBBISH-DATA-472

This is not what I need, and was wondering what, if anything, could be done in order to modify my regex to stop this from happening...
I was wondering if it is possible to statically define say TEST,TESTING and WORKING somehow within the original regex? So that I can grab them and not WRONGON and RUBBISH.

A:

You could use a non-capturing group (?: to separate what words you want to include. Also its not necessary to have L\d{1}, you can simply use L\d
RE.Pattern = "(L\d-\w{2}-(?:TEST(?:ING)?|WORKING)-DATA-\d{3,4})"

See Live demo

