fork(26) download
  1. # OPs original case.
  2. echo 'there there are are multiple lexical errors in this line line' | sed 's/\([a-z]\+[ ,\n]\+\)\1/\1/g'
  3.  
  4. # Now add a space after 'line'
  5. echo 'there there are are multiple lexical errors in this line line ' | sed 's/\([a-z]\+[ ,\n]\+\)\1/\1/g'
  6.  
  7. # To fix the original case..move the word separator outside the capture group
  8. echo 'there there are are multiple lexical errors in this line line' | sed -e 's/\([a-z]\+\)[ ,\n]\1/\1/g'
  9. # THAT ALONE DOES NOT WORK!!!
  10.  
  11. # Add a word boundary requirement.
  12. echo 'there there are are multiple lexical errors in this line line' | sed -e 's/\b\([a-z]\+\)[ ,\n]\1/\1/g'
  13. # THAT WORKS!!!
  14.  
Success #stdin #stdout 0.03s 5312KB
stdin
Standard input is empty
stdout
there are multiple lexical errors in this line line
there are multiple lexical errors in this line 
there are multiplexical errors in this line
there are multiple lexical errors in this line