Image

Imageamoe wrote in Imagedevelopers

Listens: Prodigy - Diesel Power

Another Perl problem.

Wanting a regex to remove one word (words being whitespace-seperated) from the start of a string and return it, kinda like a shift() for strings. It needs to remove them so that it can be used in a loop, btw. I came up with this

$string =~ s/^\b(.+?)\b//;

But when tested out on the string 'We waited for the bus.', it works first time, correctly returning "We", and the remaining string being " waited for the bus.", but when used again $1 seems to remain unmodified, still containing "We". This suggests to me that we need to bypass the space at the start, and match from the first non-whitespace character until the next word boundary, which led me to change it to this:

$string =~ s/^\b(\w.+?)\b//;

Nope, exactly the same output as before.

Any clues?