Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the Java RegEx equivalent to the SQL LIKE clause of "%A%B%"?

Tags:

java

regex

What is the Java RegEx equivalent to the SQL LIKE clause of "%A%B%"?

Pretty basic question, I'm just learning the Java Regex flavor.

like image 303
Andy Avatar asked Nov 19 '10 22:11

Andy


1 Answers

I think this is it pattern wise: .*A.*B.*

I'll edit and add more for specific java calls.

EDIT #1:

//simplest match
"".matches( ".*A.*B.*" );

String foo = "";
foo.matches( ".*A.*B.*" );

EDIT #2: From the API docs:

Pattern p = Pattern.compile(".*A.*B.*");
Matcher m = p.matcher("your-string-here");
boolean b = m.matches();

Also, I would take a look at RegexBuddy, its not free but it does have means to generate snippets for many languages, test & parse regex's, etc.

like image 195
javamonkey79 Avatar answered Oct 06 '22 01:10

javamonkey79