I'm totally new to reg-ex and for valid string
Getting verification (! , & amp; nbsp; , (, ) , | < Combination of logical operators like / strong>) For example, if & amp; | should be ineligible by the joint because AND OR
should come together. Similarly, possible invalid combinations and | , | & Amp; , () , ! & Amp; , & Amp ;! etc
Below is a string example
1 (ABC) and (dfg). (ZXC) - Pass as all operators are connected correctly 2.! (ABC | DKJ) and VBN - Pass 3.! (ADF and (! And (BER | CTY)). DGH = failed! & Amp; Combined 4! (ABC and DKJ) & amp;; VBN - & amp; | I know that I know in many ways as if I do not have the verification, to check the check and reject
method. But istring
< I can use the> code> method in thereg-ex
injava
To avoid matching just the invalid operator combo, you can use negative letterhead reagues like this:
^ (?!. *? (& Amp; \\ || \\ | & Amp; | \\ (\\) | | & Amp ;; & amp ;;))
Use it for multiline input such as multiline
With option:
pattern p = Pattern.compile ("(? M) ^ (?!. *? ([& Amp; [| |] | [] | ([] | | \\ (\\))))
with a string input You can do this to:
Boolean value = Input.matches ("(?!! *? (& Amp; [!!] | [[(| ] And | \\ (\\)). + ");
No comments:
Post a Comment