I searched for a while how to use the logical AND operation in regular expressions in Java, and failed.
I tried to do as recommended in a similar topic:
(?=match this expression)(?=match this too)(?=oh, and this)
and it does not work. Even simple examples with? = Returns false:
String b = "aaadcd"; System.out.println(b.matches("(?=aa.*)"));
I also read that (expression X)(expression Y)
should work like X AND Y
, but it works like X OR Y
What am I doing wrong?
Added: I tried to add .*
At the end. Still not working.
For example:
[2-9]?[0-9]{5,9}||1[2-9][0-9]{1,2}||120[0-9]{1,1}||119[0-9]
= X - returns false if the number is less than 1190
[0-9]{1,3}||1[0-0][0-9]{1,2}||11[0-8][0-9]{1,1}||119[0-2]
= Y - returns false if the number is greater than 1992.
String a = "1189"; a.matches(X) // return false a.mathes(Y) // return true a.matches((?=X)(?=Y).*) // return true, but should return false.
Added: Yes, my regular expression is incorrect. To blame. The problem is resolved. Thank you all very much!
Mikhail
source share