Java Regex:捕获两个字符之间的组,然后在捕获的组中匹配字符

发布于 2025-01-27 15:34:48 字数 698 浏览 2 评论 0原文

问题:如何首先捕获两个字符之间的组,第二个匹配该匹配组中的字符?

给定输入:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

多彩岁月 2025-02-03 15:34:48

您可以将捕获组放在外观之后,然后选择匹配,然后捕获asterix

(?<==|!=|>|>=|<|<=|IN|NOT IN)(?:\"(\*))?.*?(?=AND|OR|$)

Regex Demo

You can place the capture group after the lookbehind, and then optionally match " followed by capturing the asterix

(?<==|!=|>|>=|<|<=|IN|NOT IN)(?:\"(\*))?.*?(?=AND|OR|$)

Regex demo

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文