正则表达式匹配代码中过多的空格
我想查找并替换下面显示的 $
之间的所有空格,并将其替换为一个空格。
注意:我手动添加了 $
来向您展示我想要匹配的内容。它们实际上并不存在于代码中 - 因为如果存在,它就无法编译!
CClient::CClient$ $(Callback& callback):
SecurityInfo$ $(NULL),
ConnectInfo$ $(NULL),
Session$ $(NULL),
Id$ $(NULL),
MyCallback$ $(callback),
{
unsigned long$ $something = 0;
ConnectionId$ $= NumberOfClients++;
SecurityInfo$ $= new SecurityInfoClass$ $();
ConnectInfo$ $= new ConnectInfoClass$ $();
这是我到目前为止所得到的:
s/(?<!^)(?: ){2,}+|\t+(?=\S)/ /g
它工作正常,但对行首的检查不起作用我预料到了。
提前致谢。
I want to find and replace all whitespace that is shown below between $
's with just a single space.
NOTE: I added the $
's manually to show you what I was looking to match. They are not actually present in the code - because if they were, it wouldn't compile!
CClient::CClient$ $(Callback& callback):
SecurityInfo$ $(NULL),
ConnectInfo$ $(NULL),
Session$ $(NULL),
Id$ $(NULL),
MyCallback$ $(callback),
{
unsigned long$ $something = 0;
ConnectionId$ $= NumberOfClients++;
SecurityInfo$ $= new SecurityInfoClass$ $();
ConnectInfo$ $= new ConnectInfoClass$ $();
Here's what I have so far:
s/(?<!^)(?: ){2,}+|\t+(?=\S)/ /g
It works OK, but the check for the beginning-of-line doesn't work as I expected.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我猜你想要类似的东西:
接受这个:
I'm guessing you want something like:
Accepted this: