我有一个我从File.ReadAllText检索的字符串:
6 11 rows processed如您所见,总是有一个整数指定此文档中的行号。 我感兴趣的是它之后的整数和“行处理”字样。 所以在这种情况下,我只对子串“11行处理”感兴趣。
因此,知道每一行将以整数开始,然后是一些空格,我需要能够隔离它后面的整数和“行处理过的”字样并将其自身返回给字符串。
有人告诉我这很容易用Regex,但到目前为止我还没有最微弱的线索如何构建它。
I have this string I have retrieved from a File.ReadAllText:
6 11 rows processedAs you can see there is always an integer specifying the line number in this document. What I am interested in is the integer that comes after it and the words "rows processed". So in this case I am only interested in the substring "11 rows processed".
So, knowing that each line will start with an integer and then some white space, I need to be able to isolate the integer that follows it and the words "rows processed" and return that to a string by itself.
I have been told this is easy to do with Regex, but so far I haven't the faintest clue how to build it.
最满意答案
这应该适合您的需要:
\d+(.*)这将搜索一个或多个数字( \d+ ),然后将所有内容放入一个组中:
. = any character * = repeater (zero or more of the preceding value (which is any character in the above () = grouping但是,杰森是正确的,因为你只需要使用分割功能
This should work for what you need:
\d+(.*)This searches for 1 or more digits (\d+) and then it puts everything afterwards in a group:
. = any character * = repeater (zero or more of the preceding value (which is any character in the above () = groupingHowever, Jason is correct in that you only need to use a split function
更多推荐
发布评论