Regex 如何在正则表达式中编写此模式?

Regex 如何在正则表达式中编写此模式?,regex,Regex,你能帮我们从下列句子中提取单词吗 从那以后,他一直领导着美国政府为中心的管理工作,并派遣了代表团前往该地区 我们怎样才能做到: He's led U.S. efforts for government-centered management ever since resulting in the missions to the area 事先非常感谢 编辑和评论: 我们感谢大家的好意。 你很难区分 > > 区域。(或者,如你的例子,美国< /代码>和区域> 。还考

你能帮我们从下列句子中提取单词吗

从那以后,他一直领导着美国政府为中心的管理工作,并派遣了代表团前往该地区

我们怎样才能做到:

He's 
led 
U.S. 
efforts 
for 
government-centered
management 
ever 
since
resulting 
in 
the  
missions 
to 
the 
area
事先非常感谢

编辑和评论:


我们感谢大家的好意。

你很难区分<代码> > <代码> > <代码>区域。<或代码>(或者,如你的例子,<代码>美国< /代码>和<代码>区域> <代码>。还考虑一个句子,比如“他在美国做过多次努力”。在句子的末尾不加倍句号。你最好得到的是相近的。

你将很难区分<代码> > <代码> > <代码>区域。<或>代码>(或者,在你的例子中,<代码>美国< /代码>和<代码>区域> <代码>。还考虑一个句子,比如“他在美国做过多次努力”。,而不是在句子末尾将句号加倍。最好的结果是接近句号。

根据您使用的regexp风格,您可以使用以下选项:

/\b(\S+[^,.])\b/
另一种方法是,将
[^,.]
替换为Unicode代码点
\p{p}

编辑:

(?:          # match either...
 (?<![A-Z]   # (as long as not preceded by A-Z
  |\betc     # or etc
  |\bca      # or ca
  |\bapprox  # or approx
 )           # ...)
 \.          # a dot
 |           # or
 ,           # a comma
)?           # if present.
(\s+|$)      # then either match whitespace or the end of the string.
一个简单得多的表达式适用于单词级别,但它将匹配
U.S
,而不是
U.S.

/\w\S+\w/

根据您使用的regexp风格,您可以使用以下选项:

/\b(\S+[^,.])\b/
另一种方法是,将
[^,.]
替换为Unicode代码点
\p{p}

编辑:

(?:          # match either...
 (?<![A-Z]   # (as long as not preceded by A-Z
  |\betc     # or etc
  |\bca      # or ca
  |\bapprox  # or approx
 )           # ...)
 \.          # a dot
 |           # or
 ,           # a comma
)?           # if present.
(\s+|$)      # then either match whitespace or the end of the string.
一个简单得多的表达式适用于单词级别,但它将匹配
U.S
,而不是
U.S.

/\w\S+\w/

对于
U.S.
您需要在正则表达式中指定该裸字。因此您的正则表达式如下所示:

\s?(U\.S\.|.*?)[., ]

这对我来说很有效。

对于
美国。
您需要在正则表达式中指定该单词。因此您的正则表达式如下所示:

\s?(U\.S\.|.*?)[., ]

这对我很有用。

在你的情况下,你可以在正则表达式上拆分

(?:(?<![A-Z])\.|,)?(\s+|$)
会分裂

He's led U.S. efforts for management, resulting in approx. 3 times the missions to the area, etc.
进入

说明:

(?:          # match either...
 (?<![A-Z]   # (as long as not preceded by A-Z
  |\betc     # or etc
  |\bca      # or ca
  |\bapprox  # or approx
 )           # ...)
 \.          # a dot
 |           # or
 ,           # a comma
)?           # if present.
(\s+|$)      # then either match whitespace or the end of the string.
(?:#匹配其中一个。。。

(?在您的情况下,可以在正则表达式上拆分

(?:(?<![A-Z])\.|,)?(\s+|$)
会分裂

He's led U.S. efforts for management, resulting in approx. 3 times the missions to the area, etc.
进入

说明:

(?:          # match either...
 (?<![A-Z]   # (as long as not preceded by A-Z
  |\betc     # or etc
  |\bca      # or ca
  |\bapprox  # or approx
 )           # ...)
 \.          # a dot
 |           # or
 ,           # a comma
)?           # if present.
(\s+|$)      # then either match whitespace or the end of the string.
(?:#匹配其中一个。。。

(?你的意思是从你的短语中删除.and,而不删除.in US?你在使用哪个正则表达式引擎?你的意思是从你的短语中删除.and,而不删除.in US?你在使用哪个正则表达式引擎?感谢所有人的回答。我们怎么能像“自我中心”这样包含连字符?@user482742:你是什么意思?你想在连字符上分开吗?不像你上面的例子中,
以政府为中心的
保持在一起?感谢所有人的回答。我们怎么能像“以自我为中心”一样包含连字符?@user482742:你是什么意思?你是否也希望在连字符上拆分,而不是像上面的示例中那样,
以政府为中心的
保持在一起?