Regex assigning multiple groups to keyword
I am trying to implement a regex that has the capability to assign a same
keyword or combination of keywords to one or multiple Named Groups.
For example I want to match ('aa' AND 'bb') OR 'cc' and assign 'aa' AND
'bb' to a group<1> and 'cc' to group<2>.
Also I can have a query like ('aa' AND 'bb') OR 'aa' and I want 'aa' AND
'bb' to be in group<1> and at the same time 'aa' to be in group<2>.
// Works to get 'aa' everywhere but cannot find a way to add 'bb' to the
group<1>
(?=(?:\s+|^)(?<1>aa)(?:\s+|$))
EDIT :
Input Example : bb is nice but not without the missingaa
Output : Does not Validate, Group<1> is null | Group<2> is null
-
Input Example : bb is nice as well as aa
Output : Validate, Group<1> : bb is nice as well as aa | Group<2> is null
-
Input Example : bb is nice but not without the missingaa or cc
Output : Validate, Group<1> is null | Group<2> is cc
-
Input Example : bb is nice as well as aa or cc
Output : Validate, Group<1> is bb is nice as well as aa | Group<2> is cc
I know that the grouping might be complicated but I am looking to have
Group<1> which is not null if aa and bb exist.
How can I achieve this behavior? Thank you for the help.
No comments:
Post a Comment