获取仅与直接前驱匹配的字符串。

huangapple go评论110阅读模式
英文:

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

Link to saved work

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

https://regexr.com/59deb

thanks

答案1

得分: 2

你可以使用这个正则表达式:(?<=, )[^,]+(?=, CL)

(?<=, ) 在匹配之前有一个逗号和空格。

[^,]+ 匹配至少一个字符,不包括逗号。

(?=, CL) 匹配后面跟着字符串", CL"。

演示:https://regex101.com/r/tMlQby/1

英文:

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

(?&lt;=, ) 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

huangapple
  • 本文由 发表于 2020年7月31日 15:36:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/63187658.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定