regular expression to remove the first word of each line
I am trying to make a regular expression that grabs the first word (including possible leading white space) of each line. Here it is:
This code does not seem to be working (see http://regexr.com?34o6m). The code is supposed to
- Begin at the start of the line
- Create a capturing group where it places the first word (with possible leading white space)
- Grab the rest of the line
- Substitute the entire line with just the inside of the first capturing group
I tried another version also:
It looks like this one fails too (http://regexr.com?34o6s). The goal here was to
- Find the first non-whitespace character.
- Look behind to make sure it has a whitespace character behind it (i.e. not the first letter of the line).
- Grab the rest of the line.
- Erase everything the expression just grabbed.
Any insight to what is going wrong would be greatly appreciated. Thanks!
You mixed up your + and *.
This means zero or more spaces followed by one or more non-spaces.
You might also want to use $1 instead of \1:
I tested it on www.altastic.com/regexinator, which as far as I know is accurate [I made it though, so it may not be ;-) ]
Try this regular expression