正则表达式匹配相同字符串中的非唯一字符(Regex match a non

编程入门 行业动态 更新时间:2024-10-22 02:49:16
正则表达式匹配相同字符串中的非唯一字符(Regex match a non-unique character in same string)

这是一个示例字符串。 我需要修复其中的更多内容:

"måde", "answer" => "råd");

在此字符串中有2个字符实例å。 我想找到一个匹配使用正则表达式的å在råd ,而忽略了å在måde

所以基本上我需要在answer之后找到一个匹配的匹配。

我认为(?<=answer)å(?=\;)会起作用,但我对此非常陌生,如果有人能指出我正确的方向,我会非常感激。

我之前尝试过问这个问题,但由于某种原因而被投票,所以我试着在这里重新制定它。 我希望它足够清楚。

Here is an example string. I have many more of these that I need to fix:

"måde", "answer" => "råd");

In this string there are 2 instances of the character å. I want find a match for the å in råd using regex, while ignoring the the å in måde.

So basically I need to find a match of an occurrence of å after answer.

I thought that (?<=answer)å(?=\;) would work, but I'm really new to this and would very much appreciate it if someone could point me in the right direction.

I tried asking this question before but got downvoted for some reason, so I tried to reformulate it here. I hope it is clear enough.

最满意答案

看后面(通常)不能是可变长度,但通过使用向前看,你告诉它匹配:

å(?!.*answer)

这匹配“å”,但仅在“回答”未出现在其后的某处。

Look behinds (typically) can't be of variable length, but by using a negative look ahead, you tell it what not to match:

å(?!.*answer)

This matches "å", but only if "answer" doesn't appear somewhere after it.

更多推荐

本文发布于:2023-08-04 13:59:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1416074.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   字符   正则表达式   非唯一   Regex

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!