0

我有如下文字。

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum 
has been the industry's standard dummy text ever since the fivec harword 1500s, when an unknown printer 
took a galley of type and scrambled it to make a type specimen fivec harword book. It has survived not
only five centuries, but also the leap into electronic typesetting, remaining essentially 
unchanged. It was popularised in the 1960s with the release of fivec harword Letraset sheets containing 
Lorem Ipsum passages, and more recently with desktop publishing software like Aldus 
PageMaker including versions of Lorem Ipsum.

这是我需要的正则表达式:

1-选择五个字符的单词。

2-第一步后选择一个空间。

3-在第二步后选择七个字符。

它应该捕获所有fivec harword字符串。我怎样才能做到这一点?

4

3 回答 3

2

使用这个:

\b\w{5}\s\w{7}\b

解释:

The regular expression:

(?-imsx:\b\w{5}\s\w{7}\b)

matches as follows:

NODE                     EXPLANATION
----------------------------------------------------------------------
(?-imsx:                 group, but do not capture (case-sensitive)
                         (with ^ and $ matching normally) (with . not
                         matching \n) (matching whitespace and #
                         normally):
----------------------------------------------------------------------
  \b                       the boundary between a word char (\w) and
                           something that is not a word char
----------------------------------------------------------------------
  \w{5}                    word characters (a-z, A-Z, 0-9, _) (5
                           times)
----------------------------------------------------------------------
  \s                       whitespace (\n, \r, \t, \f, and " ")
----------------------------------------------------------------------
  \w{7}                    word characters (a-z, A-Z, 0-9, _) (7
                           times)
----------------------------------------------------------------------
  \b                       the boundary between a word char (\w) and
                           something that is not a word char
----------------------------------------------------------------------
)                        end of grouping
----------------------------------------------------------------------
于 2013-03-22T11:09:20.513 回答
1

这应该可以解决问题

(^|\W)\w{5}\s\w{7}($|\W)

(^|\W)字符串或非单词字符的开头。

\w{5}一串 5 个单词字符

\s空间

\w{7}一串 7 个单词字符

($|\W)字符串结尾或非单词字符

如果您特别希望字符串周围有空格(而不是标点符号等),请将两者都替换\W\s

于 2013-03-22T11:06:12.813 回答
0

试试这个

\b[a-zA-Z]{5}\s[][a-zA-Z]{7}\b

\b 表示边界

[a-zA-Z] 所有 Alpha 投注

{5} 5 个字符,前面的表达式

\s 单个空格

于 2013-03-22T11:15:44.687 回答