Personally, I don't use Java, but this RegExp could do the trick:
([^\" ])*(\\\".*?\\\")*
Attempting an expression using RegExBuddy, it generates this code, looks great to me:
try { Pattern regex = Pattern.compile("([^\" ])*(\\\".*?\\\")*", Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE); Matcher regexMatcher = regex.matcher(subjectString); while (regexMatcher.find()) { for (int i = 1; i <= regexMatcher.groupCount(); i++) {
At least in Python, it works fine:
import re text = """ este es un texto de prueba "para ver como se comporta " la funcion sobre esto "para ver como se comporta " la funcion sobre esto "o sobre otro" lo q sea """ ret = "" print text reobj = re.compile(r'([^\" ])*(\".*?\")*', re.IGNORECASE) for match in reobj.finditer(text): if match.group() <> "": ret = ret + match.group() + "|" print ret
PabloG
source share