[英]I have regex to split string to words, numbers and punctuation marks list. How to make “a-z” and “0-9” single elements of list?
It's looks so: 它看起来如此:
string[] lines = Regex.Split(line, @"\s+|(?!^)(?=\p{P})|(?<=\p{P})(?!$)");
It's split "ASds22d. asd ,156"
to "ASds22d" + "." + "asd" + "," + "156"
它将
"ASds22d. asd ,156"
拆分为"ASds22d" + "." + "asd" + "," + "156"
"ASds22d" + "." + "asd" + "," + "156"
. "ASds22d" + "." + "asd" + "," + "156"
。
Here is problem with strings like "az", "0-9" or variations like "ac" and "4-5". 这是“az”,“0-9”等字符串或“ac”和“4-5”等变体的问题。 My regex split
"az 1-9"
to "a" + "-" + "z" + "1" + "-" + "9"
but i need just "az" + "1-9"
. 我的正则表达式将
"az 1-9"
分为"az 1-9"
"a" + "-" + "z" + "1" + "-" + "9"
但我只需要"az" + "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. 您可以尝试这样的事情。这不会分裂
-
。如果您有任何需要拆分的示例-
需要它可以再次进行OR
编辑。
See demo. 见演示。
https://regex101.com/r/iS6jF6/3 https://regex101.com/r/iS6jF6/3
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.