gogagubi
gogagubi

Reputation: 1015

Write regex pattern in java to work for multiple && condition

This is pattern ^\w+\.\w+ *= *.+$ that works for parent.child1=value11. This is pattern ^\w+\.\w+ *= *.+ *&& *\w+\.\w+ *= *.+$ that works for this parent.child1=value1 && parent.child2=value2. Is there an easier way to write a RegEx pattern that will work for both? Even more to work for multiple && condition(cond1 && cond2 && cond3...)?

Upvotes: 0

Views: 50

Answers (1)

anubhava
anubhava

Reputation: 785126

You may use this regex to match single ot multiple conditionals:

^\w+\.\w+ *= *\S+(?: *&& *\w+\.\w+ *= *\S+)*$

RegEx Demo

Repetition in (?: *&& *\w+\.\w+ *= \S+)* will let me match 0 or more occurrences of your conditions thus allowing it to match all of your desired expressions.

Upvotes: 2

Related Questions