正则表达式:连接/连接 html 标签中用空格分隔的单词中的字母

正则表达式:连接/连接 html 标签中用空格分隔的单词中的字母

我有这个 HTML 标签:

<title>c o n n e c t s t h e l e t t e r s i n w o r d s</title>

必须成为:

<title>connects the letters in words</title>

我尝试了这个,但是没有用:

寻找:(<title>)(.+?\s+.+?)(</title>)

替换为:\1\2\3

答案1

  • Ctrl+H
  • 找什么:(?:<title>|\G)\S*\K(?:\h+(\h)|\h+)(?=.*</title>)
  • 用。。。来代替:$1
  • 查看 环绕
  • 查看 正则表达式
  • Replace all

解释:

(?:         # non capture group
    <title>     # literally, open tag
  |           # OR 
    \G          # restart from last match position
)           # end group
\S*         # 0 or more non space
\K          # forget all we have seen until this position
(?:         # non capture group
    \h+         # 1 or more horizontal space
    (\h)        # group 1, 1 horizontal space
  |           # OR
    \h+         # 1 or more horizontal space
)           # end group
(?=         # positive lookahead, make sure we have, after:
    .*          # 0 or more any character
    </title>    # literally, close tag
)           # end lookahead

截图(之前):

在此处输入图片描述

截图(之后):

在此处输入图片描述

相关内容