missing last character in perl regex

后端 未结 3 1230
情话喂你
情话喂你 2021-01-29 06:22

(log doggies) (log needs)

^\\(log (.*)[^)]\\)\\s*\\(log (.*)[^)]\\)$

It works with the exception of missing character at the end \"s\" as:

相关标签:
3条回答
  • 2021-01-29 06:27

    It looks like your .* should be [^)]*, i.e. *any number of characters that are not closing parentheses. Giving

    ^\(log ([^)]*)\)\s*\(log ([^)]*)\)$
    

    Or you could fetch all instances of (log xxx) with

    while ( $s =~ /\(log ([^)]*)\)/g ) {
        print $1, "\n";
    }
    
    0 讨论(0)
  • 2021-01-29 06:37
    ^\(log (.*)\)\s*\(log (.*)\)$
    

    You don't need to negate the ).

    0 讨论(0)
  • 2021-01-29 06:45

    The [^)] eats your s-es. Why do you need it?

    my $s = '(log doggies) (log needs)';
    say for $s =~ /^\(log (.*)\)\s*\(log (.*)\)$/;
    

    Output:

    doggies
    needs
    
    0 讨论(0)
提交回复
热议问题