我的文件包含一些行,例如
"This is a string." = "This is a string's content."
" Another \" example \"" = " New example."
"My string
can have several lines." = "My string can have several lines."
我需要提取子字符串:
This is a string.
This is a string's content.
Another \" example \"
New example.
My string
can have several lines.
My string can have several lines.
这是我的代码:
String regex = "\".*?\"\\s*?=\\s*?\".*?\"";
Pattern pattern = Pattern.compile(regex,Pattern.DOTALL);
Matcher matcher = pattern.matcher(file);
目前,我可以得到“=”的左右部分。但是当我的子字符串包含“\””时,我的正则表达式就不能正确地完成工作。
任何人都可以帮我写正确的正则表达式吗?我尝试了 \"^[\\"] 而不是 \",但它没有用..
提前谢谢。