更新时间:2022-10-19 13:43:04
所以你真正想做的是删除一个前面有字母数字字符的点,然后是一个或两个破折号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.