I've searched for a while how to use logical operation AND in regular expressions in Java, and have failed.
I've tried to do as recommended in similar topic:
(?=match this expression)(?=match this too)(?=oh, and this)
and it doesn't work. Even simple examples with ?= returns false:
String b = "aaadcd";
System.out.println(b.matches("(?=aa.*)"));
Also I've 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:
Tried to add .*
in the end. Still don't work.
For a example:
[2-9]?[0-9]{5,9}||1[2-9][0-9]{1,2}||120[0-9]{1,1}||119[0-9]
= X - return false if 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 - return false if 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: Yep, my regexp is not correct. My bad. The problem solved. Thank everyone very much!