Regex matching EOL character within a string

▼魔方 西西 提交于 2020-01-05 08:07:19

问题


I'm trying to find LF characters that appear between double quotes. The text file I'm searching has field-value pairs in this format

    msgid "text 1"
    msgstr "text 2"

I'm trying to find if LF characters appear within text 1 or text 2 strings. I have tried "[^"\r\n]*\n[^"\r\n]*" but it just picks up " msgstr "


回答1:


This regex :

if ($subject =~ m/"([^"\r\n]*?[\r\n]+[^"\r\n]*?)"\s*$/m) {
    $result = $1;
}

When applied to these strings :

msgid "text 1 " 
msgstr "text 2"
msgstr "something with new 
line"

Will produce this output :

something with new 
line


来源:https://stackoverflow.com/questions/7740435/regex-matching-eol-character-within-a-string

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!