It's looks so:
string[] lines = Regex.Split(line, @"\s+|(?!^)(?=\p{P})|(?<=\p{P})(?!$)");
It's split "ASds22d. asd ,156"
to "ASds22d" + "." + "asd" + "," + "156"
.
Here is problem with strings like "a-z", "0-9" or variations like "a-c" and "4-5". My regex split "a-z 1-9"
to "a" + "-" + "z" + "1" + "-" + "9"
but i need just "a-z" + "1-9"
.
Can someone fix this regex?
\s+|(?!^|-)(?=\p{P})|(?<=\p{P})(?<!-)(?!$)
You can try something like this.This will not split on -
.If you have any examples where split on -
is required it can OR
ed again.
See demo.
https://regex101.com/r/iS6jF6/3
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With