简体   繁体   中英

Regex to get specific Character after occurrence of a specific string

I am trying to create a Regex to get a value after 'New Serial Number'

Input String : [EXT] EOL Resolved : 343250; Serial Number : OLD123 ; New Serial Number : NEW123; UPS Tracking Number : UPSTRN123; [EXT] EOL Resolved : 343250; Serial Number : OLD123 ; New Serial Number : NEW123; UPS Tracking Number : UPSTRN123;

I need output to be 'NEW123'

Tried :

Match(%K00291;"(?<=New Serial Number :)(.*;)";true)

But I am getting output as : NEW123; UPS Tracking Number : UPSTRN123; NEW123; UPS Tracking Number : UPSTRN123;

You should use .*? ( *? - zero or more but as few as possible ) instead of .* (which ends up to the last ; ) in order to stop matching at the nearest ; :

 ..."(?<=New Serial Number :)(.*?)(?=;)"...

Finally, if you don't want to include trailing ; into match, let's put it as (?=;)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM