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
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