Hi all,
I have a problem in applying a regex in my Java code.
My text string is like this (String myString)
name: Abc Def;
blah: 1 2 3;
second name: Ghi;
I need to extract the name information (Abc Def). Name can contain a string of 1+ words. All the properties (name, blah, second name) are spaced with some whitespaces at the beginning
The code I'm trying to use is
String patternStr = "\\s{2,}name:\\s([\\w ]*\\w+);";
Matcher matcher = Pattern.compile(patternStr).matcher(myString);
if (matcher.matches())
System.out.println(matcher.group(1));
My regex seems working fine with online tools (regex: \s{2,}name:\s([\w ]*\w+);) but when I port it to java code it simply doesn't work. Any idea of what I'm missing?
Thanks a lot
Edit: If I use matcher.find() it works fine.