Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 使用Perl正则表达式在数字中插入空格_Regex_Perl - Fatal编程技术网

Regex 使用Perl正则表达式在数字中插入空格

Regex 使用Perl正则表达式在数字中插入空格,regex,perl,Regex,Perl,我有以下文本数据: 1290 15 46 372 4 -1914 670 8 -894 1016 12 554 我正在尝试此操作以插入空格: '1290' -replace "(?<=(\d{3})),$&" '-1914' -replace "(?<=(\d{3})),$&" 或: 您可以使用以下选项进行匹配: (?<=\d)(?=(\d{3})

我有以下文本数据:

1290        15      46 
372         4       -1914 
670         8       -894 
1016        12      554 
我正在尝试此操作以插入空格:

'1290' -replace "(?<=(\d{3})),$&"
'-1914' -replace "(?<=(\d{3})),$&"
或:


您可以使用以下选项进行匹配:

(?<=\d)(?=(\d{3}))

(?您可以使用以下正则表达式:

(\d)(?=(\d{3})+(?!\d))
看到和

输出:

1 290        15      46
372          4       -1 914
670          8       -894
1 016        12      554

@choroba,谢谢你的回复!但我无法安装Number::Format。我有windows,所以我会使用regex。(还有xml::Twig我无法安装此模块。greats@rHow您尝试安装它了吗?出现了什么错误?@Choroba,谢谢您的回复。我不记得了。但我会做evinig并打开英语新闻主题。此时我会这样做:。格式化图片($number,“#############)"伟大的@r.@Stribizev我知道有人会指出这一点..我必须说..,不清楚的问题!大家好。非常感谢你们的回答!来自@stribiz works fin的东西,但不是个人的。iha使用了:oderwise with padre“#!”/usr/bin/perl my$ins=“14589965321”$ins=~(?@stribiz我明白了:您使用的浏览器版本已经过时,regex101.com不再支持。强烈建议您升级浏览器。很抱歉给您带来不便。@Arnold:什么意思?。我的regex工作正常。regex101.com在我的浏览器中运行良好,.soorry“1.1。“我的错误。所有人都非常感谢波尔斯卡!!”欢迎你。如果我的答案对你有用的话,请考虑一下投票。
(\d)(?=(\d{3})+(?!\d))
#!/usr/bin/perl
# your code goes here
my $ins = "1290        15      46\n372         4       -1914\n670         8       -894\n1016        12      554";
$ins =~ s/(\d)(?=(\d{3})+(?!\d))/$1 /g;
print "$ins\n";
1 290        15      46
372          4       -1 914
670          8       -894
1 016        12      554