[英]Regular Expression how to get the value inside double quotes including double quotes
這是我想要實現的
a) (123)
=> 123
b) ("123")
=> 123
c) ""123""
=> "123"
d) (""#12.20.AA"")
=> "#12.20.AA"
前兩個雙引號內的有效字符是"
, .
, #
和:
我嘗試使用此[\\w\\"\\.:#=/\\-\\+\\t\\s]+
但顯然對於情況b返回""123""
,對於情況c返回""#12.20.AA""
對於情況b, "123"
。
任何想法如何避免第一個雙引號和只拳頭(和尾巴相同)?
此表達式對我有用:
\(?.*?"?("?[#:\d\.AA]+("(?="))?)"?.*\)?
您將在第一個匹配組中找到您的匹配項。 與一些評論相同的正則表達式:
\(?
.*? # ? prevent the * to be eager
"? # include the " if there
( # group 1 (your match)
"?[#:\d\.AA]+
("(?="))? # positive lookahead: include the first " in case there are two of them
)
"?
.*\)?
在此演示鏈接上,您可以輕松地對該表達式進行進一步的試驗。
通常,如果您需要有關正則表達式的權威信息,這是一個很好的鏈接 。
希望這可以幫助。
if ($txt =~ /"/) {
s/^[^"]*"//;
s/"[^"]*$//;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.