如何匹配点下划线下划线“.__” [英] how to match dot underscore underscore ".__"
问题描述
我正在尝试用 __
和替换
, .__
的所有出现。 - -
以下内容:
文章。 __authors .__ item
...将成为...
article__authors__item
...和...
bucket .__ water.-half
......会变成...
bucket__water-half
我从<$ c开始$ c> .__ part并提出 \\\\ .__ \ b
作为我的正则表达式但是 http://gskinner.com/RegExr/ 似乎不喜欢它...
虽然 \\\\\\\\\还有更好的方法吗?
干杯,
尼克
所以你真正想做的是删除一个前面有字母数字字符的点,然后是一个或两个破折号nderscores?然后你可以使用积极的先行断言来做到这一点:
搜索 \\\\。(?= __ | - )
并替换为空字符串。
如果您还想确保在下划线/破折号后跟随另一个字母数字字母,您可以:
搜索 \ b \。(?= __(?= [A-Za-z0-9])| -\b)
并替换为空字符串。
I'm trying to replace all occurences of .__
with __
and .-
with -
so the following:
article.__authors.__item
...would become...
article__authors__item
...and...
bucket.__water.-half
...would become...
bucket__water-half
I started with the .__
part and came up with \b\.__\b
as my regex but http://gskinner.com/RegExr/ doesn't seem to like it...
This works for the 2nd match though \b\.-\b
Is there a better way?
Cheers, Nick
So what you actually want to do is to remove a dot that is preceded by an alphanumeric character and followed by either a dash or two underscores? Then you can do this using positive lookahead assertions:
Search for \b\.(?=__|-)
and replace with the empty string.
If you also want to make sure that another alphanumeric letter follows after the underscores/dash, you can:
Search for \b\.(?=__(?=[A-Za-z0-9])|-\b)
and replace with the empty string.
这篇关于如何匹配点下划线下划线“.__”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!