/.* # Stuff ( # START capturing to $1 [$\ \#\%>~] # Any single space, $, #, %, > or ~ | # OR \[* # 0 or more [s \w* # 0 or more word characters (a-zA-Z0-9_) \@* # 0 or more @s \-* # 0 or more -s \w* # more word characters \% # Exactly 1 % \]* # 0 or more ]s | # OR \[*\w*\@*\-*\w*\#\]* # As above, but with a # instead of % | # OR \[*\w*\@*\-*\w*\$\]* # As above, but with a $ | # OR \[*\w*\@*\-­*\w*>\]* # As above, but with no terminator # (will therefore match any terminator) | # OR \\\[\\e\[0m\\\]\ \[0m # the sequence: \[\e[0m\\] [0m ) # END of $1 \s? # 0 or 1 spaces /x #### /.* # Stuff ( # START capturing to $1 \[* # 0 or more [s \w* # 0 or more word characters \@* # 0 or more @s \-* # 0 or more -s \w* # more word characters [$\ \#\%>~] # exactly 1 space, $, #, %, > or ~ \] # exactly 1 ] (are you missing a * ?) | # OR \\\[\\e\[0m\\\]\ \[0m # the sequence: \[\e[0m\\] [0m ) # END of $1 \s? # 0 or 1 spaces /x #### /.* # Stuff ( # START capturing to $1 \ # exactly 1 space | # OR \[* # 0 or more [s \w* # 0 or more word characters \@* # 0 or more @s \-* # 0 or more -s \w* # more word characters [$\#\%>~] # exactly 1 of $, #, %, > or ~ \]* # 0 or more ]s | # OR \\\[\\e\[0m\\\]\ \[0m # the sequence: \[\e[0m\\] [0m ) # END of $1 \s? # 0 or 1 spaces /x #### /.* # Stuff ( # START capturing to $1 \ # exactly 1 space | # OR \[? # 0 or 1 [ \w* # 0 or more word characters \@? # 0 or 1 @ [-\w.]* # 0 or more word chars, dots and hyphens eg w-w.w-.w [$\#\%>~] # exactly 1 of $, #, %, > or ~ \]? # 0 or 1 ] | # OR \\\[\\e\[0m\\\]\ \[0m # the sequence: \[\e[0m\\] [0m ) # END of $1 \s? # 0 or 1 spaces /x