需要帮助在括号处停止
Need help stopping at parenthesis
我是正则表达式的新手,真的需要一些帮助。我正在尝试创建一个正则表达式,在下面的示例中查找第一个 space 和左括号之前的所有内容。基本上,我试图只保留一个或多个国家/地区名称并排除后面的所有内容。
福克兰群岛(马尔维纳斯群岛)
我试过了,但没用:
(\w+)(?=[\s+(\w+\s+])
使用
^.*?(?=\s*\()
请参阅此处 proof。
说明
--------------------------------------------------------------------------------
^ the beginning of the string
--------------------------------------------------------------------------------
.*? any character except \n (0 or more times
(matching the least amount possible))
--------------------------------------------------------------------------------
(?= look ahead to see if there is:
--------------------------------------------------------------------------------
\s* whitespace (\n, \r, \t, \f, and " ") (0
or more times (matching the most amount
possible))
--------------------------------------------------------------------------------
\( '('
--------------------------------------------------------------------------------
) end of look-ahead
我是正则表达式的新手,真的需要一些帮助。我正在尝试创建一个正则表达式,在下面的示例中查找第一个 space 和左括号之前的所有内容。基本上,我试图只保留一个或多个国家/地区名称并排除后面的所有内容。
福克兰群岛(马尔维纳斯群岛)
我试过了,但没用:
(\w+)(?=[\s+(\w+\s+])
使用
^.*?(?=\s*\()
请参阅此处 proof。
说明
--------------------------------------------------------------------------------
^ the beginning of the string
--------------------------------------------------------------------------------
.*? any character except \n (0 or more times
(matching the least amount possible))
--------------------------------------------------------------------------------
(?= look ahead to see if there is:
--------------------------------------------------------------------------------
\s* whitespace (\n, \r, \t, \f, and " ") (0
or more times (matching the most amount
possible))
--------------------------------------------------------------------------------
\( '('
--------------------------------------------------------------------------------
) end of look-ahead