tags:

views:

60

answers:

2

Edit: thanks for the reg answers below. What if my goal is to strictly emulate mysql like operator,which seems to ignore \n in between characters?

what's java equivalent of mysql string search operator 'like'?

I need to search for strings that might have \n end of line or other white spaces between them. for example, abc\n efg

string.indexOf("abcefg") doesn't work.

+8  A: 

This is a good scenario for regex in Java. See details in the Pattern class JavaDoc. You can use these patterns in String.matches

akf
+2  A: 

Try regular expressions.

http://java.sun.com/docs/books/tutorial/essential/regex/

http://java.sun.com/javase/6/docs/api/java/util/regex/Pattern.html

 Groups and capturing

Capturing groups are numbered by counting their opening parentheses from left to right. In the expression ((A)(B(C))), for example, there are four such groups:

1       ((A)(B(C)))
2       (A)
3       (B(C))
4       (C)
saugata