admin管理员组文章数量:1391943
So, I have a regex problem I'm trying to solve and can't figure out.
I need to find a string that starts with R or K, but not followed by a P, continuing onwards til it finds another R or K which isn't followed by a P, with a "&" symbol in between the two.
For example, "RQKRQEQERPELAEG&EQSEKQERPLEQRD" should find the string "RQEQERPELAEG&EQSEK". However, I can't do it, and I don't know how. Help please.
I tried using negative lookbehind and positive lookbehind and all sorts of other shit, and I can't figure it out.
So, I have a regex problem I'm trying to solve and can't figure out.
I need to find a string that starts with R or K, but not followed by a P, continuing onwards til it finds another R or K which isn't followed by a P, with a "&" symbol in between the two.
For example, "RQKRQEQERPELAEG&EQSEKQERPLEQRD" should find the string "RQEQERPELAEG&EQSEK". However, I can't do it, and I don't know how. Help please.
I tried using negative lookbehind and positive lookbehind and all sorts of other shit, and I can't figure it out.
Share Improve this question asked Mar 14 at 8:14 user29974491user29974491 29 10 | Show 5 more comments2 Answers
Reset to default 2You don't specify a regex flavour so I shall assume PCRE2. With whitespace for legibility:
(?x)
(?&delim)
(?&hasamp)
(?&delim)
(?(DEFINE)
(?<delim> [KR](?!P) )
(?<other> [KR](?=P) | [^KR] )
(?<hasamp> (?&other)* & (?&other)* )
)
https://regex101/r/dVPOzg/1
Since no kind of regular expression was specified, I'll use PCRE (or Python, or ECMAScript, or Java 8, or.NET 7.0 (C#)).
[KR](?:[^KR]|.(?=P))*&.*?[KR](?!P)
https://regex101/r/huVaTT/1
本文标签:
版权声明:本文标题:string - How to find the start of a substring that isn't proceeded by a certain character, and ends with a character not 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744668317a2618667.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
.*
to consume the beginning and\K
to reset with some regex like^.*\K[RK](?!P)[A-Z]*&[A-Z]*?[RK](?!P)
– bobble bubble Commented Mar 14 at 9:50RQKRQEQERPELAEG&EQSEK
? – jhnc Commented Mar 14 at 19:27RQK
(which I queried above)). Maybe:[KR](&|[KR]P&|[^KRP&]([KR]P|[[^KR])*&)([KR]P|[^KR])*[KR]([^P]|$)
– jhnc Commented Mar 15 at 20:08