[英]Regex/grep to pull dot path out of string
鑒於以下字符串可能會在各種文檔中以各種不同的格式出現多次,因此我想引述引號之間的部分。 我只想要滿足以下條件的字符串。 以“(在兩個引號之間)開頭和結尾,並且在字符串中具有1個或多個點(。)。
@CheckWith(value = PasswordCheck.class,message =“ validation.password.blah.foo”)
以下正則表達式為我提供了字符串validation.password.blah的前三個部分,但缺少.foo
(\")([a-zA-Z]{1,}\.{1}){1,}
請嘗試以下操作:
"([a-zA-Z]{1,}\.[a-zA-Z.]{1,})"
請注意,通常可以使用+
代替{1,}
,但是我不確定grep是否支持不帶擴展選項的功能。
說明:
" # match a literal '"' character
( # start capture group
[a-zA-Z]{1,} # one or more letters
\. # match a literal '.' character
[a-zA-Z.]{1,} # one or more letters or '.' characters
) # end capture group
" # match a literal '"' character
我認為您要查找的正則表達式是這樣的: "[a-zA-Z]+(\\.[a-zA-Z]+)+
您應該記住,它不會包含last "
並且僅接受點之間的字母。
如果您有egrep
(或grep -E
),則可以使用
"([a-zA_Z]+\.)+[a-zA-Z]+"
(引號是正則表達式的一部分,如果需要,請轉義)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.