在字符串正则表达式C#中查找单词,然后查找值编号(Find a word and then a value number in string regular expression C#)
我是正则表达式使用的新手,并且在2天内我正在搜索如何从字符串中提取特定数据,但没有成功。
这个字符串是一个较长字符串的部分字符串,我需要找到一个参数,然后获取它的值:
\rRoll Off = 0.25\rSINE = OFF\rSymbol Rate = 1.000000\rBit Rate = 1.322253目标 :找到参数Symbol Rate,并使用C#通过正则表达式获取其值1.000000 (只需存储该值)。
如果有人可以帮我解决这个问题,将会非常有帮助。
谢谢!
I'm new with regular expression uses, and for 2 days I'm searching how to pull a specific data from a string, but without success.
This string is a partial from a longer string, I need to find a parameter and then get its value:
\rRoll Off = 0.25\rSINE = OFF\rSymbol Rate = 1.000000\rBit Rate = 1.322253Goal: find the parameter Symbol Rate and get its value 1.000000 (need to store just the value) by regular expression using C#.
It will be very helpful if someone can help me with that issue.
Thank you!
最满意答案
向后看
用这个:
var myRegex = new Regex(@"(?<=Symbol Rate\s*=\s*)[0-9.]+"); string resultString = myRegex.Match(yourString).Value; Console.WriteLine(resultString);说明
lookbehind (?<=Symbol Rate\s*=\s*)断言前面的是Symbol Rate ,可选的空格, = ,可选的空格 [0-9.]+一个或多个数字或句点的字符参考
Lookahead和Lookbehind Zero-Length Assertions 掌握前瞻和外观Lookbehind
Use this:
var myRegex = new Regex(@"(?<=Symbol Rate\s*=\s*)[0-9.]+"); string resultString = myRegex.Match(yourString).Value; Console.WriteLine(resultString);Explanation
The lookbehind (?<=Symbol Rate\s*=\s*) asserts that what precedes is Symbol Rate, optional whitespace, =, optional whitespace [0-9.]+ one or more chars that are digits or a periodReference
Lookahead and Lookbehind Zero-Length Assertions Mastering Lookahead and Lookbehind更多推荐
发布评论