I want to catch a single quoted text , however escaped single quote (\’) shouldn’t be considered a delimiter,
for example:
This ‘wasn\’t the best’ day
shall return
- wasn’t the best
Thanks.
I’ve tried this:
public static List<String> cropQuoted (String s) {
Pattern p = Pattern.compile("\\'[^']*\\'");
Matcher m = p.matcher(s);
ArrayList found = new ArrayList();
while(m.find()){
found.add(m.group().replaceAll("\'", ""));
System.out.println(m.group().replaceAll("\'", ""));
}
return found;
}
but it fails to catch “\’best’days’to come”
(?<!\\\\)'means “every'with no\before it”Using this we can create something like this
(?<!\\\\)'.*?(?<!\\\\)'Lets test it
Is that you are looking for?