You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

正则匹配:将ue替换为ü但排除tuell类含ue词汇的技术咨询

Solution for Replacing "ue" with "ü" (Excluding Cases Like "tuell")

I get it, dealing with German orthography regex replacements can be tricky when you need to carve out specific exceptions. Let’s break this down to solve your exact problem:

The Target Regex Pattern

The core here is using a negative lookahead to skip any "ue" that’s immediately followed by "ll"—the exact pattern in words like Aktuell you want to leave untouched. Here’s the regex you need:

ue(?!ll)

How It Works

Let’s break down the components:

  • ue: Matches the literal character sequence "ue"
  • (?!ll): This is a negative lookahead assertion. It checks that the characters right after "ue" are not "ll". If they are, the match fails entirely, so those "ue" instances won’t be replaced.

Test Case Verification

Let’s put this to the test with your example words:

  • Aktuell → The "ue" is followed by "ll", so no replacement happens (stays Aktuell)
  • ueber → The "ue" isn’t followed by "ll", so it becomes über
  • luegen → Becomes lügen
  • tuell → Remains tuell (since "ue" is followed by "ll")

PHP Implementation

Since you confirmed preg_replace works for you, here’s how to plug this regex in:

$originalText = "Aktuell ueber luegen tuell";
$modifiedText = preg_replace('/ue(?!ll)/', 'ü', $originalText);
// Output: "Aktuell über lügen tuell"

Expanding for More Exceptions

If you later need to exclude other "ue" patterns (like "ue" followed by "nd" for words similar to your exception), you can extend the negative lookahead:

ue(?!ll|nd)

Just be sure to test all your target vocabulary to make sure the regex behaves exactly as you need it to!

内容的提问来源于stack exchange,提问作者tommsen

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 07:00:15