I need to build ONE regular expression that can detect ALL the following strings and ONLY those.
// 'NC_' or 'NG_', can be from 6 to 9 digits after the underscore.
// '.' is static, can be 1 or 2 digits after the '.'
"NC_123456.12" or "NG_123456.12"
// Example: /^N(G|C)_[0-9]{6,9}\.[0-9]{1,2}/
// 'LRG_' is static, can be 1 or more digits after the underscore
"LRG_1234"
// Example: /LRG_[1-9][0-9]*/
// 'UD_' is static, can be 1 or more digits after the underscore
"UD_123456789012"
// Example: /UD_[0-9]+/
So the problem i have is not that i need the regex for finding the strings individually, but that I need ONE regex that can catch ALL the above situations. I don’t know if it’s even possible, but I want to thank everyone beforehand who is willing to try!
You can combine case 2 and three. Also, your regex for case 1 is a bit awkward.
If you use a variant that supports it, you can use
The regex examples you give in the comments are a bit confusing. In case the number after LRG_ must not start with a 0, you have to use the following solution:
The general principle stands: combine your branches with a
|.