Chaitanya Vardhan
Chaitanya Vardhan

Reputation: 43

obtain the String matching only the immediate predecessor

I have the below String

"8 IN, Ball Valve, Trunnion, Gen manu, CL 900, BW, Body LTCS, Metal Seat, Gear Operated, Trim Alloy 825, Full Bore, NACE MR 0175/ISO 15156 -with extended pup-piece as pipe schedule. VBFW 91Z08"

I need to obtain the string Gen Manu thats available before the , CL and After the previous comma (the comma after Trunnion in this case). I have tried below so far

(?=\,).(?=.\w).*.(?=\,.CL)

I am unable to perform a partial match

below is where I saved my work, any help regarding this is greatly appreciated

https://regexr.com/59deb

thanks

Upvotes: 0

Views: 120

Answers (1)

Alex G
Alex G

Reputation: 1917

You can use this regex: (?<=, )[^,]+(?=, CL)

(?<=, ) before the match there is a comma followed by space.

[^,]+ the match is at least one character excluding any commas.

(?=, CL) match should be followed by the string ", CL"

Demo: https://regex101.com/r/tMlQby/1

Upvotes: 2

Related Questions