What would be the best way to delete every second word (or better: string separated from adjacent strings by whitespace) from a line of text in perl?
from this:
- Mn Gordon Npmsc Snell Npmsc . Fe
i would like to retrieve only this:
- Gordon Snell .
I’ve tried to write a regular expression modeling this, but I’ve failed so far. Any suggestions would be appreciated!
s/(\s*\S+\s+)\S+\s*/$1/gseems to get you there, preserving whitespace at the beginning of the line and after the last undeleted word. It’s not clear whether you want to preserve whitespace before or after the deleted word (or whether it matters).