Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

reg expression problem

Status
Not open for further replies.

kaancho12

Technical User
Feb 22, 2005
191
hi,
i am trying to do regex match with the following program below:
import java.util.regex.Pattern;
import java.util.regex.Matcher;

public class GREP {

public static void main(String[] args) {
String input = new String("APO asdsa");
String apo ="(?m)^"+"apo"+".*$";

// modify regular expression to match beginning of line (^) and end of line ($)
// the (?m) makes ^ and $ match beginning and end of line (instead of file)

Pattern papo = Pattern.compile(apo, Pattern.CASE_INSENSITIVE);


Matcher matcher2 = papo.matcher(input);


if (mmatcher2.find()) {
System.out.println(matcher2.group());
System.out.println("found");
}
}
}
all works except it works for strings which i dont want it to be matched with also. for example if my input string is "APOLASAS" it matches with that also. I am not sure if java regex has the option of matching with just the word "apo" by itself like in php where preg_match has "/b" which can be used.
any suggestions?
thanks
 
never mind.
"\b" does work with regex.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top