need some help. Wanna replace all method names in code with rule:
需要一些帮助。想用代码替换代码中的所有方法名称:
MethodName -> methodName (need for cpp translation).
Unfortunatelly, I need to escape in my Regex all cases that started with new
.
不幸的是,我需要在我的正则表达式中逃避所有以新的开头的情况。
My regex:
`[>\\.\\s]+[A-Z]+[a-zA-Z0-9_]*\\({1}`
It matches to
它符合
`>MethodName(`, `.MethodName(` ` MethodName(`
but also in last case can be new ClassName
.
但在最后一种情况下也可以是新的ClassName。
How to avoid this case?
如何避免这种情况?
2 个解决方案
#1
2
You can use this regex:
你可以使用这个正则表达式:
(?<!new)[>.\s]+[A-Z]+\w*\(
(?<!new)
is a negative lookbehind, it will ensure that the method name is not preceded by the keyword new
.
(?
I also:
- changed
[a-zA-Z0-9_]
to\w
since it's equivalent; - remove the quantifier
{1}
which was redundant.
将[a-zA-Z0-9_]更改为\ w,因为它是等效的;
删除多余的量词{1}。
#2
0
Do you need to find with leading space? If not:
你需要找到领先的空间吗?如果不:
- First character may by > or .
- Followed by capital letter
- Follwed by zero or more letter,number or underline
-
Followed by (
其次是 (
[>|\.]([A-Z][a-zA-Z0-9_])*\(
第一个字符可以>或。
其次是大写字母
由零个或多个字母,数字或下划线表示
#1
2
You can use this regex:
你可以使用这个正则表达式:
(?<!new)[>.\s]+[A-Z]+\w*\(
(?<!new)
is a negative lookbehind, it will ensure that the method name is not preceded by the keyword new
.
(?
I also:
- changed
[a-zA-Z0-9_]
to\w
since it's equivalent; - remove the quantifier
{1}
which was redundant.
将[a-zA-Z0-9_]更改为\ w,因为它是等效的;
删除多余的量词{1}。
#2
0
Do you need to find with leading space? If not:
你需要找到领先的空间吗?如果不:
- First character may by > or .
- Followed by capital letter
- Follwed by zero or more letter,number or underline
-
Followed by (
其次是 (
[>|\.]([A-Z][a-zA-Z0-9_])*\(
第一个字符可以>或。
其次是大写字母
由零个或多个字母,数字或下划线表示