0

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?

suspense_hey
  • 85
  • 2
  • 11

1 Answers1

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

The fourth bird
  • 154,723
  • 16
  • 55
  • 70