【问题标题】:Regex for getting all words and punctuations from a string with html用于从带有 html 的字符串中获取所有单词和标点符号的正则表达式
【发布时间】:2016-10-01 03:34:34
【问题描述】:

我在想出一个正则表达式语句时遇到了麻烦,该语句从一个看起来像这样的字符串中获取所有单词和标点符号

<p>hello my name is foo.</p><p>I like to go to the bar.</p>

我想要的结果是……

'你好' '我的' '名字' '是' 'foo.' ..等

需要排除段落标签和空格。正则表达式将进入使用 bash 的 git diff --word-diff-regex='insert regex here'

谢谢

编辑

git 使用 POSIX 作为它的正则表达式。不支持环顾四周

【问题讨论】:

  • 试试&lt;[^&gt;]+&gt;(*SKIP)(*F)|\S+(如果PCRE可用)。
  • 只有当我在 标签之前添加空格时才有效
  • 所以,似乎安装了 PCRE。试试&lt;[^&gt;]+&gt;(*SKIP)(*F)|[^\s&lt;]+
  • 抱歉,在 regex101.com 中有效,但是当我用 git 运行它时,它说正则表达式无效
  • 您使用什么语言/工具?

标签: regex posix


【解决方案1】:

您可以像这样使用正则表达式:

<.*?>|([\w.]+)

Working demo

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-10-15
    • 1970-01-01
    • 2017-11-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多