【问题标题】:Find a word with regex formula every time the next character it's different by a letter/number or underscore每次下一个字符与字母/数字或下划线不同时,使用正则表达式查找一个单词
【发布时间】:2021-09-04 04:08:21
【问题描述】:

每次下一个字符与字母、数字或下划线不同时,我都需要找到单词“hello”。 下图中有一个例子(绿色没问题):

example

如何使用正则表达式来做到这一点?

谢谢 ;-)

【问题讨论】:

标签: regex regex-group regex-negation regexp-replace


【解决方案1】:

您正在寻找的正则表达式:

hello[^\w]{1}

“如果后面没有字母、数字或 _,请抓住单词 hello”。

现场示例:https://regex101.com/r/1vzn8m/1/

【讨论】:

  • 谢谢,非常有用 :-) 但是当字母、数字或下划线不同时,我不想选择 'hello' 之后的下一个字符。只是“你好”,有可能吗?
  • 当然,你只能使用捕获组捕获你好:(hello)[^\w]{1} "hello" 将存入 1 美元。
猜你喜欢
  • 2012-08-14
  • 1970-01-01
  • 1970-01-01
  • 2022-09-27
  • 2010-09-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多