I would like to be able to match a string literal with the option of escaped quotations. For instance, I\'d like to be able to search \"this is a \'test with escaped\\\' val
If I understand what you're saying (and I'm not sure I do) you want to find the quoted string within your string ignoring escaped quotes. Is that right? If so, try this:
/(?
Basically:
Ok, I've tested this in Java (sorry that's more my schtick than Python but the principle is the same):
private final static String TESTS[] = {
"'testing 123'",
"'testing 123\\'",
"'testing 123",
"blah 'testing 123",
"blah 'testing 123'",
"blah 'testing 123' foo",
"this 'is a \\' test'",
"another \\' test 'testing \\' 123' \\' blah"
};
public static void main(String args[]) {
Pattern p = Pattern.compile("(? %s%n", test, m.group(1));
} else {
System.out.printf("%s doesn't match%n", test);
}
}
}
results:
'testing 123' => testing 123
'testing 123\' doesn't match
'testing 123 doesn't match
blah 'testing 123 doesn't match
blah 'testing 123' => testing 123
blah 'testing 123' foo => testing 123
this 'is a \' test' => is a \' test
another \' test 'testing \' 123' \' blah => testing \' 123
which seems correct.