简体   繁体   English

正则表达式以查找字符,但排除包含该字符的某些单词

[英]regex to find characters but exclude some words that have that characters

I'm trying to find all occurences of ue and replace it with ü , but not for occurences like tuell . 我正在尝试查找ue的所有出现并将其替换为ü ,但不是针对tuell这样的出现 Reason is that german words like Aktuell should not be Aktüll afterwards. 原因是像Aktuell这样的德语单词之后不应再称为Aktüll I tried different approaches with lookahead and lookbehind but could not get it working. 我尝试了不同的方法,先行后顾,但无法正常工作。 I used https://regex101.com/ to test the expression. 我使用https://regex101.com/来测试表达式。 focus is on finding via regex, replacing via PHP preg_replace is not an issue. 重点是通过正则表达式查找,通过PHP preg_replace替换不是问题。

You may use a (?!ll) negative lookbehind to make sure the next 2 chars are ll right after ue : 您可以使用(?!ll)负回顾后,以确保在未来2个字符是ll之后ue

ue(?!ll)

See the regex demo 正则表达式演示

See more details about lookarounds here . 在此处查看有关环顾四周的更多详细信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM