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

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

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

+5
source share
3 answers

I think this is a sample example: .*A.*B.*

I will 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();

In addition, I would look at RegexBuddy , its not free, but it has the means to create fragments for many languages, testing and parse regex's, etc.

+10
source

".? A.? B". . ? , . () " ", * 0 - .

0
Pattern p = Pattern.compile(".*?A.*?B.*");
Matcher m = p.matcher(str);
if (m.matches()) {
...
0

All Articles