在C#,regex中只获取字符串的一部分 [英] Get just a part of a string in C#, regex
问题描述
您好,
我有一些文件行,我必须从字符串中获取第一个字符。
文本为:
...
(空格)UWORD(空格)/ *数据类型* /
(空格)UBYTE(空格)/ *数据类型* /
....
我必须得到UWORD,UBYTE没有任何空格且没有/ *数据类型......
我尝试了一个又一个角色,但没有任何东西,在Regex中,我无法弄清楚我该怎么做。
非常感谢!
我尝试过:
正则表达式=新正则表达式((我不知道),RegexOptions.None);
//正则表达式
或者如果有另一种方法......
你可以试试:
string rx = @ ^ \ * *(? <类型> [AZ] +)\s * * 。 blockquote>
你想要捕获的内容将在命名的groupeType
。
希望这会有所帮助。有几个免费工具可以构建正则表达式;你应该尝试其中一个:)
Hello,
I have some lines of a file and i have to get from it as a string just the firsts characters.
The text is:
...
(spaces) UWORD (spaces) /* data type */
(spaces) UBYTE (spaces) /* data type */
....
I have to get the "UWORD", "UBYTE" without any space and without "/*data type..."
I tried with character by character but nothing, and in Regex i can't figured out how can i do it.
Thanks a lot!
What I have tried:
Regex pattern = new Regex("(I DON'T KNOW)", RegexOptions.None);
// for regex
or if there is another method...
You could try:
string rx = @"^\s*(?<Type>[A-Z]+)\s*.*
"
What you want to capture would be captured under the named groupeType
.
Hope this helps. There exist several free tools out there to build regular expressions ; you should try one of them :)
这篇关于在C#,regex中只获取字符串的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!