英文:
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
thanks
英文:
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
thanks
答案1
得分: 2
你可以使用这个正则表达式:(?<=, )[^,]+(?=, CL)
(?<=, )
在匹配之前有一个逗号和空格。
[^,]+
匹配至少一个字符,不包括逗号。
(?=, CL)
匹配后面跟着字符串", CL"。
演示:https://regex101.com/r/tMlQby/1
英文:
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"
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论