This discussion is archived
5 Replies Latest reply: Dec 12, 2012 5:21 AM by 939520 RSS

Regex Pattern matching

766669 Newbie
Currently Being Moderated
Hi there, sorry to bother, i been having problem with regex expression macthing.

String criteria = "Mary-Anna";
String regexWord = "((\\w+)[^A-Z](\\w+))";
Pattern patternWord = Pattern.compile(regexWord);
Matcher matcherWord = patternWord.matcher(criteria);
if (matcherWord.find()) {
System.out.println(matcherWord.group(1));
} else {
System.out.println("nomatch");
}

this return Mary-Anna which is what i needed

String criteria = "Mary' 'Anna"; // 2 single quotes
String regexWord = "((\\w+)[^A-Z](\\w+))";
Pattern patternWord = Pattern.compile(regexWord);
Matcher matcherWord = patternWord.matcher(criteria);
if (matcherWord.find()) {
System.out.println(matcherWord.group(1));
} else {
System.out.println("nomatch");
}

But am not sure why if i put in 2 single qoute and it return only Mary ??

am trying to get the pattern to match a [name]+[non a-z chars]+[name]

thanks

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points