I get a string from a array list:
array.get(0).toString()
gives TITLE = ‘blabla’
I want the string blabla, so I try this :
Pattern p = Pattern.compile('(\'.*\')'); Matcher m = p.matcher(array.get(0).toString()); System.out.println('Title : ' + m.group(0));
It doesn’t work: java.lang.IllegalStateException: No match found
I also try:
Pattern p = Pattern.compile('\'.*\''); Pattern p = Pattern.compile('\'.*\''); Pattern p = Pattern.compile('\\\'.*\\\'');
Nothing matches in my program but ALL patterns work on http://www.fileformat.info/tool/regex.htm
Any Idea? Thanks in advance.
A couple of points:
The Javadoc for Matcher#group states:
That is, before using group, you must first use
m.matches(to match the entire sequence), orm.find(to match a subsequence).Secondly, you actually want
m.group(1), sincem.group(0)is the whole pattern.Actually, this isn’t so important here since the regexp in question starts and ends with the capture parentheses, so that group(0) is the same string as group(1), but it would matter if your regexp looked like:
'TITLE = (\'.*\')'Example code: