在字符串正则表达式C#中查找单词,然后查找值编号(Find a word and then a value number in string regular expression C#)

编程入门 行业动态 更新时间:2024-10-26 15:22:58
字符串正则表达式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.322253

Goal: 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 period

Reference

Lookahead and Lookbehind Zero-Length Assertions Mastering Lookahead and Lookbehind

更多推荐

本文发布于:2023-07-30 08:25:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1336703.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   单词   编号   正则表达式   Find

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!