Regex for string in C#
I have string on C#:
string buf = "\r\n \r\n \r\n 103E\r\n \r\n \r\n \r\n \r\n \r\ntest1 \r\n \r\n \r\n test2\r\n \r\n \r\n \r\n \r\n 开发者_开发百科 \r\n \r\n \r\n \r\n x16\r\n \r\n"
I want to get the strings
1. 103E
2. test1
3. test2
4. 16
How to do it using regex.
Try this:
var separator = new string[] { "\r", "\n", " ", " " };
var result = buf.Split(separator, StringSplitOptions.RemoveEmptyEntries);
// result == { "103E", "test1", "test2", "x16" }
Note that, if your input is arbitrary HTML, you should use an HTML parser.
\S+
will match one or more non-whitespace characters. That should get you started.
source: http://www.mikesdotnetting.com/Article/46/CSharp-Regular-Expressions-Cheat-Sheet
精彩评论