2014-12-03 50 views
1

我有內容。如何在正則表達式中獲得製表符匹配

 Welcome  to  the  world. 

我想從出發點得到匹配計數。不在內容選項卡內。

我試過但沒有工作。它得到所有的標籤計數。

use strict; 
    use warnings FATAL => 'all'; 
    my $cnt = qq(   welcome  to  the  world); 

    my $number =() = $cnt =~ /(\t)/gi; 
    print join("\n", $number);exit; 

感謝提前。請任何人幫忙。

+0

你希望要打印什麼樣的價值? – 2014-12-03 04:20:16

回答

2

我假設你想要從字符串開頭的製表符的匹配數。

my $number =() = $cnt =~ /\G\t/g; 
+0

謝謝它的工作原理.. – depsai 2014-12-03 04:31:41

6

您可以通過\G

my $number =() = $cnt =~ /\G\t/g; 

錨固解決這個問題,但它會更有效地使用

$cnt =~ /^\t*/; 
my $number = $+[0]; 
+0

(+1)爲更有效的方式。 – hwnd 2014-12-03 04:43:58

+0

感謝您的答案,它也適用。 @ikegami – depsai 2014-12-04 04:25:33