I have been trying to write regular expression which find a specific word at specific position in javascript adobe classification rule builder
DI_NEO_OP_BRA_CRC_LRN_DIS_EP_NA_CON_UC_NA
I want to get result as CON from above line in adobe classification rule builder code which i have been using to get the desired output is
^(.+?)_(.+?)_(.+?)_(.+?)_(.+?)_(.+?)_(.+?)_(.+?)_(.+?)_(.+?)_(.+?)$
however this code only give output as any word which is at 10th position? I want to get output which matches CON and is at 10th position.
2
Answers
Try it on regex101.com.
You can use a single capture group, and then match CON followed by either
_
or the end of the string:Explanation
^
Start of string(?:[^_n]*_){9}
Repeat 9 times matching any character except_
or a newline, and then match_
(CON)
Capture group 1, match CON(?:_|$)
Match either_
or assert the end of the stringRegex demo