[英]Regex to match string which has words followed by whitespace then digits dot or hyphen and words followed by space and then (some info)
我有一個具有以下格式的字符串: name category (more info)
例如: Foo Bar-8.io 5.61.0-rc-1 (data)
我需要一個正則表達式,它基本上過濾掉符合上述格式的字符串。
名稱可以是帶有空格的字母數字, -
和.
類別可以以數字開頭,后跟單詞,包括點或連字符
數據可以是任何包含在()
中的.*
我試過這個: ^[\w\s]+.*\s.*\(.*\)$
但似乎沒有涵蓋上述模式。
利用
^(.*)\s+(\S+)\s+\((.*)\)$
請參閱正則表達式證明。
解釋
--------------------------------------------------------------------------------
^ the beginning of the string
--------------------------------------------------------------------------------
( group and capture to \1:
--------------------------------------------------------------------------------
.* any character except \n (0 or more times
(matching the most amount possible))
--------------------------------------------------------------------------------
) end of \1
--------------------------------------------------------------------------------
\s+ whitespace (\n, \r, \t, \f, and " ") (1 or
more times (matching the most amount
possible))
--------------------------------------------------------------------------------
( group and capture to \2:
--------------------------------------------------------------------------------
\S+ non-whitespace (all but \n, \r, \t, \f,
and " ") (1 or more times (matching the
most amount possible))
--------------------------------------------------------------------------------
) end of \2
--------------------------------------------------------------------------------
\s+ whitespace (\n, \r, \t, \f, and " ") (1 or
more times (matching the most amount
possible))
--------------------------------------------------------------------------------
\( '('
--------------------------------------------------------------------------------
( group and capture to \3:
--------------------------------------------------------------------------------
.* any character except \n (0 or more times
(matching the most amount possible))
--------------------------------------------------------------------------------
) end of \3
--------------------------------------------------------------------------------
\) ')'
--------------------------------------------------------------------------------
$ before an optional \n, and the end of the
string
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.