Regex将返回值移动到函数参数
我有很多类似以下的句子:Regex将返回值移动到函数参数,regex,Regex,我有很多类似以下的句子: PlayerInfo[playerid][pValue] = cache_get_value_name_int(i, "field"); 但是,由于库的更改,我现在需要将此行替换为以下内容: cache_get_value_name_int(i, "field", PlayerInfo[playerid][pValue]); 问题是PlayerInfo[playerid][pValue]是一个变化的“词”。每隔一行替换一行。“场”也会发生同样的事情 我有很多行需要替
PlayerInfo[playerid][pValue] = cache_get_value_name_int(i, "field");
但是,由于库的更改,我现在需要将此行替换为以下内容:
cache_get_value_name_int(i, "field", PlayerInfo[playerid][pValue]);
问题是PlayerInfo[playerid][pValue]是一个变化的“词”。每隔一行替换一行。“场”也会发生同样的事情
我有很多行需要替换,至少有几百行,所以我想找一些正则表达式来轻松替换它们
有解决方案吗?在记事本++中,您可以使用以下正则表达式:
([^\s]+) = cache_get_value_name_int\(i,\s*("[^"]+")\s*\);
它搜索一定数量的非空格字符(捕获为组1),然后是=
(如果间距可以变化,您可能需要使用\s*=\s*
),然后是缓存\u get\u value\u name\u int(i,
,一个包含在“
(捕获为组2)中的字符串,然后是一个尾随的)
和
并将其替换为
cache_get_value_name_int\(i, $2, $1\);
请注意,您可能需要在位置中添加\s*
,以考虑不同的间距
如果值i
也可以更改,则可以使用此正则表达式捕获该字符串:
([^\s]+) = cache_get_value_name_int\((\w+),\s*("[^"]+")\s*\);
并将其替换为:
cache_get_value_name_int\($2, $3, $1\);
- Ctrl+H
- 查找内容:
^(\S+)=(缓存\u获取\u值\u名称\u int\(\w+,“\w+”)
- 替换为:
$2,$1
- 检查环绕
- 检查正则表达式
- 全部替换
说明:
^ # beginning of line
(\S+) # group 1, 1 or more non space characters
= # space, equal sign, space
( # start group 2
cache_get_value_name_int\( # literally
\w+ # 1 or more word characters
, # comma, space
"\w+" # 1 or more word characters surrounded with quotes
) # end group 2
$2 # content of group 2
, # comma & space
$1 # content of group 1
cache_get_value_name_int(i, "field", PlayerInfo[playerid][pValue]);
更换:
^ # beginning of line
(\S+) # group 1, 1 or more non space characters
= # space, equal sign, space
( # start group 2
cache_get_value_name_int\( # literally
\w+ # 1 or more word characters
, # comma, space
"\w+" # 1 or more word characters surrounded with quotes
) # end group 2
$2 # content of group 2
, # comma & space
$1 # content of group 1
cache_get_value_name_int(i, "field", PlayerInfo[playerid][pValue]);
给定示例的结果:
^ # beginning of line
(\S+) # group 1, 1 or more non space characters
= # space, equal sign, space
( # start group 2
cache_get_value_name_int\( # literally
\w+ # 1 or more word characters
, # comma, space
"\w+" # 1 or more word characters surrounded with quotes
) # end group 2
$2 # content of group 2
, # comma & space
$1 # content of group 1
cache_get_value_name_int(i, "field", PlayerInfo[playerid][pValue]);
屏幕截图:
^ # beginning of line
(\S+) # group 1, 1 or more non space characters
= # space, equal sign, space
( # start group 2
cache_get_value_name_int\( # literally
\w+ # 1 or more word characters
, # comma, space
"\w+" # 1 or more word characters surrounded with quotes
) # end group 2
$2 # content of group 2
, # comma & space
$1 # content of group 1
cache_get_value_name_int(i, "field", PlayerInfo[playerid][pValue]);
您打算用什么来做更改?记事本++我想简单的全局搜索和替换应该足以匹配第一行,并替换为第二行。所有行都不同,比如PlayerInfo[playerid][pValue]可以是任何其他变量,比如“foo”这就是为什么我要一个RegexOK你能更新你的问题让它更清楚吗