Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我无法为这个问题设置一个更好的标题,但我的问题是:
给定一行形式:
int a,b,var1,var2;
我需要将其转换为表格的一行
s(a);s(b);s(var1);s(var2);
到目前为止,我有这个:
s/\b(\w)[,;]/s\(\1\);/g
但它只会将其转换为
int s(a);s(b);s(var1);s(var2);
我不需要看到这个int部分。这可以只使用一个正则表达式来完成吗?
int
您可以使用正则表达式的非捕获部分并将其设为可选,如下例所示:
$_ = "int a,b,var1,var2;"; s/(?:^\w+\s+)?([^;,]+)[;,]/s(\1);/g; print $_
输出