Perl - 使用regexp删除字符串中的第一个单词

Imp*_*nce 2 regex string perl

我是Perl和reg-ex的新手,我试图删除字符串中的第一个单词(或文本文件中一行中的第一个单词),以及它后面的任何空格.

例如,如果我的字符串是'one two abd123words',我想删除'one '.

我尝试的代码是:$line =~/(\S)$/i;
但这只能给我最后一句话.
如果它有任何区别,我试图删除的单词是一个输入,并存储为$ arg.

Bir*_*rei 10

要删除每行的第一个单词,请使用:

$line =~ s/^\S+\s*//;
Run Code Online (Sandbox Code Playgroud)

编辑解释:

s/.../.../            # Substitute command.
^                     # (Zero-width) Begin of line.
\S+                   # Non-space characters.
\s*                   # Blank-space characters.
//                    # Substitute with nothing, so remove them.
Run Code Online (Sandbox Code Playgroud)