Regex to get all character to the right of first space?

前端 未结 4 502
时光说笑
时光说笑 2021-01-14 21:05

I am trying to craft a regular expression that will match all characters after (but not including) the first space in a string.

Input text:

foo bar b         


        
4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-14 21:13

    You don't need look behind.

    my $str = 'now is the time';
    # Non-greedily match up to the first space, and then get everything after in a group.
    $str =~ /^.*? +(.+)/; 
    my $right_of_space = $1; # Keep what is in the group in parens
    print "[$right_of_space]\n";
    

提交回复
热议问题