用于将带引号的字符串与转义引号相匹配的 Java 正则表达式
我知道已经有很多像我这样的问题,但我没有找到适用于 Java 的答案。所以我写了一个新问题。
我有包含如下内容的文本文件:
key1 = "This is a \"test\" text with escapes using '\\' characters"; key2 = 'It must work with \'single\' quotes and "double" quotes';
我需要一个与双引号(或单引号)中的值匹配的正则表达式。此正则表达式必须支持转义引号和转义反斜杠。 正则表达式必须与 Java 标准 Pattern/Matcher 类一起使用。
I know there are already many questions like mine but I found no answer which works in Java. So I write a new question.
I have text files with content like this:
key1 = "This is a \"test\" text with escapes using '\\' characters"; key2 = 'It must work with \'single\' quotes and "double" quotes';
I need a regular expression which matches the values in the double-quotes (or single-quotes). This regular expression must support the escaped quotes and escaped backslashes.
The regular expression must work with Java standard Pattern/Matcher classes.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试这个正则表达式:
并作为字符串文字:
Try this regular expression:
And as a string literal: