Java Regex:捕获两个字符之间的组,然后在捕获的组中匹配字符
问题:如何首先捕获两个字符之间的组,第二个匹配该匹配组中的字符?
给定输入:
atribute="value1" AND atrribute="*value2"
问题1: 我想捕获两个字符之间的组,无限次。
正则解决方案:
(?<==|!=|>|>=|<|<=|IN|NOT IN).*?(?=AND|OR|$)
捕获的组:
"value1"
"*value2"
问题2: 我想匹配捕获的组中的角色(S)
尝试的正则解决方案1:
(\*)(?<==|!=|>|>=|<|<=|IN|NOT IN).*?(?=AND|OR|$)
尝试的正则解决方案2:
[*](?<==|!=|>|>=|<|<=|IN|NOT IN).*?(?=AND|OR|$)
我的问题:上述两个尝试的解决方案均未捕获星号输入字符串。我该如何实现?
Question: How can I first capture a group(s) between two characters, and second match a character within that matched group(s)?
Given Input:
atribute="value1" AND atrribute="*value2"
Problem 1:
I want to capture a group between two characters, unlimited number of times.
Regex solution:
(?<==|!=|>|>=|<|<=|IN|NOT IN).*?(?=AND|OR|$)
Captured groups:
"value1"
"*value2"
Problem 2:
I want to match a character within the captured group(s)
Attempted regex solution 1:
(\*)(?<==|!=|>|>=|<|<=|IN|NOT IN).*?(?=AND|OR|$)
Attempted regex solution 2:
[*](?<==|!=|>|>=|<|<=|IN|NOT IN).*?(?=AND|OR|$)
My issue: neither of the above attempted solutions capture the asterisks in the input string. How can I achieve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将捕获组放在外观之后,然后选择匹配,然后捕获asterix
Regex Demo
You can place the capture group after the lookbehind, and then optionally match
"
followed by capturing the asterixRegex demo