'Java Regex: capture group between two characters and then match character within captured group

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?



Solution 1:[1]

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 The fourth bird