It is really easy. Here is the difference:
To convert the mysql regular expression to java, basically add ".*" To each end of the regular expression or otherwise convert it from a βpartialβ match to a full match.
Here are some examples to demonstrate:
Java
"xyz".matches("y"); // false - only matches part of the input "xyz".matches(".*y.*"); // true "xyz".matches("[xyz]"); // false - only matches one char, but String is 3 chars "xyz".matches("[xyz]+"); // true
MySQL
select 'xyz' regexp 'y'; -- 1 (ie true) select 'xyz' regexp '.*y.*'; -- 1 (ie true) select 'xyz' regexp '[xyz]'; -- 1 (ie true) select 'xyz' regexp '[xyz]+'; -- 1 (ie true)
source share