Regarding this question, what about adding special characters to the mix? And also saving the spaces into the list as well.
Example
This is a string, that "will be" highlighted when your 'regular expression' matches something!!!
Gives me
This
is
a
string
,
that
"will be"
highlighted
when
your
'regular expression'
matches
something
!
!
!
But i wasn't able to make it work with special characters as well...
I tried (?=[^A-Za-z0-9])|(?<=[^A-Za-z0-9])|[\\s\"']+|\"[^\"]*\"|'[^']*'
,
which results in
This
is
a
string ,
that
" will
be "
highlighted
when
your
' regular
expression '
matches
something
!
!
!
EDIT I managed to find the regex i needed myself
(\"[^\"]*\")|\\W|\\w+
This will split all words, whitespaces and special characters. It also keeps everything that are within double quotes as one element by itself