正则表达式:查找引号内的首次出现

时间:2018-08-16 17:03:56

标签: regex

我有这样的多行文字:

sometext "F1" "some other text;" "some other text;"
sometext "1" "some other text;"
sometext "`" "some other text;"
sometext "Tab" "some other text;"
sometext "CapsLock" "some other text;" "some other text;"
sometext "Shift" "some other text;"
sometext "\" "some other text;"
sometext "K" "some other text;"
sometext "ins" "some other text;"
sometext "downarrow" "some other text;" "some other text;"
sometext "Num Lock" "some other text;"
sometext "num5" "some other text;"
sometext "numenter" "some other text;"

我需要获取每行第一引号内的值。 我尝试过"(.*?)",但它会在“”中找到每个值。

2 个答案:

答案 0 :(得分:1)

要获取双引号中第一次出现的值,您可以添加锚点来声明行^的开头,然后使用否定的character class {{1 }}。您的比赛将在第一个捕获组中:

^[^"]*"(.*?)"

或者您也可以使用否定的字符类来捕获双引号之间的内容:

^[^"]*"([^"]+)"

答案 1 :(得分:0)

您需要使用反斜杠ccom.google.gson.JsonSyntaxException: 2018-08-16T06:00:00 caused by: java.text.ParseException: Failed to parse date ["2018-08-16T06:00:00']: No time zone indicator (at offset 0) Caused by: java.lang.IllegalArgumentException: No time zone indicator

对引号进行转义

尝试 \"