gpt4 book ai didi

php - 使用 regexr 工具识别 (weat)her

转载 作者:搜寻专家 更新时间:2023-10-31 21:22:23 24 4
gpt4 key购买 nike

我正在使用这个工具 http://regexr.com/3fvg9我想在 regexxr 工具中标记这个(weat)her。

       (weath)er is good.   // i want to mark this word
(weather is go)od. // i want to mark this word

请帮帮我。

最佳答案

由于无法使用正则表达式检查单词是否“已知”,我建议先提取您需要的这些部分,然后使用一种拼写词典来检查单词是否正确。它不会 100% 准确,但仍优于纯正则表达式。

你需要提取带括号的粘合词部分的表达式是

(?|([a-zA-Z0-9]+)\(([a-zA-Z\s]+)\)|\(([a-zA-Z\s]+)\)([a-zA-Z0-9]+))

参见 regex demo at regex101支持 PHP 正则表达式。

正则表达式匹配分支重置组内的 2 个备选方案,其中不同分支中的所有捕获组都以相同的 ID 开头编号:

  • ([a-zA-Z0-9]+)\(([a-zA-Z\s]+)\) - 第 1 组(([a-zA -Z0-9]+)) 匹配 1+ 个字母数字字符,然后是 (,然后是第 2 组 (([a-zA-Z\s]+)) 匹配 1+ 个字母和空格,然后匹配 )
  • | - 或
  • \(([a-zA-Z\s]+)\)([a-zA-Z0-9]+) - (, 然后第 1 组 (([a-zA-Z\s]+)) 匹配 1+ 个字母和空格,),然后是第 2 组 (([a -zA-Z0-9]+)) 匹配 1+ 个字母数字字符

关于php - 使用 regexr 工具识别 (weat)her,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43993769/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com