正则表达式帮助 [英] regular expressions help

查看:86
本文介绍了正则表达式帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试之前的示例中的文本字符串的值。

ds用于数字,s用于字符串,文本字符串用于具有多于一个或两个值的

字符串。我正在尝试使用正则表达式和

.groups方法。请帮忙。


d | d | d |文本字符串1 || s | s ||| dd.dd | ss |文本字符串

2 |||||||||||||||||||||||||||文本字符串2


我只想要一串text1

I am trying to the values of string of text in the sample before. The
ds are for digits and s is for string and string of text is for a
string with more than one or two values. I am trying to use regex and
the .groups method. Please help.

d|d|d|string of text 1||s|s|||dd.dd|ss|string of text
2||||||||||||||||||||||||||string of text 2

I only want string of text1

推荐答案

我想从整个字符串中获取第4项

d | d | d | string of text 1 || s | s ||| dd.dd | ss | text of string

2 ||||||||||||||||||||| |||||文本串2

1 | 1 | 1 | ABCDEF ..... XYZ 1 || A | A ||| 11.11 | AB | ABCDEF ..... XYZ

2 ||||||||||||||||||||||||||| ABCDEF ..... XYZ 2

我只需要显示文本字符串1,而不是d | d | d |文本字符串1 ||

s | s ||| dd.dd | ss |文本字符串2 ||||||||||||||||||||||||||字符串

text 2.


1月9日,12:14 * pm,supercrossk ... @ gmail.com写道:
I want to grab the 4th item from the entire string of this
d|d|d|string of text 1||s|s|||dd.dd|ss|string of text
2||||||||||||||||||||||||||string of text 2
1|1|1|ABCDEF.....XYZ 1||A|A|||11.11|AB|ABCDEF.....XYZ
2||||||||||||||||||||||||||ABCDEF.....XYZ 2

I only need string of text 1 for display, not d|d|d|string of text 1||
s|s|||dd.dd|ss|string of text 2||||||||||||||||||||||||||string of
text 2.

On Jan 9, 12:14*pm, supercrossk...@gmail.com wrote:

我正在尝试的文本字符串的值之前的样品。

ds用于数字,s用于字符串,文本字符串用于具有多于一个或两个值的

字符串。我正在尝试使用正则表达式和

.groups方法。请帮忙。


d | d | d |文本字符串1 || s | s ||| dd.dd | ss |文本字符串

2 |||||||||||||||||||||||||||一串文字2


我只想要一串text1
I am trying to the values of string of text in the sample before. The
ds are for digits and s is for string and string of text is for a
string with more than one or two values. I am trying to use regex and
the .groups method. Please help.

d|d|d|string of text 1||s|s|||dd.dd|ss|string of text
2||||||||||||||||||||||||||string of text 2

I only want string of text1


我不确定我理解这个问题,但我认为这会有所帮助。


你可以创建一个名字将它括在paranethsis中并添加?< name> ;.


例如,我的代码中有以下正则表达式模式

" _( ?< WellName> [AH] \\d {1,2})_"


这用于捕捉Well Designation(来自AH和,就可以从更长的字符串中获取$>
然后是1或2位数。

Regex.Match(&SomeText_B7_MoreText" ,_(?< WellName> [AH] \\\\ {1,2})_")。Groups [" WellName"]。Value;


将返回B7 (如果我在某个地方没有错字......)

Ethan

" su ************ @ gmail。 COM"写道:
I am not sure I understand the question, but I think this will help.

You can create a named group by enclosing it in paranethsis and add ?<name>.

For example, I have the following Regex pattern in my code
"_(?<WellName>[A-H]\\d{1,2})_"

This is used to capture just the Well Designation (a letter from A-H and
then 1 or 2 digits) from a longer string as long as that pattern is
surrounded by underscores.
Regex.Match("SomeText_B7_MoreText","_(?<WellName>[A-H]\\d{1,2})_").Groups["WellName"].Value;

Would return "B7" (If I don''t have a typo somewhere...)
Ethan
"su************@gmail.com" wrote:

我正在尝试之前的示例中的文本字符串的值。

ds用于数字,s用于字符串,文本字符串用于具有多于一个或两个值的

字符串。我正在尝试使用正则表达式和

.groups方法。请帮忙。


d | d | d |文本字符串1 || s | s ||| dd.dd | ss |文本字符串

2 |||||||||||||||||||||||||||文本字符串2


我只想要一串text1

I am trying to the values of string of text in the sample before. The
ds are for digits and s is for string and string of text is for a
string with more than one or two values. I am trying to use regex and
the .groups method. Please help.

d|d|d|string of text 1||s|s|||dd.dd|ss|string of text
2||||||||||||||||||||||||||string of text 2

I only want string of text1


我会尽量让它更清晰。


1 | 2 | 3 |这是是我要显示的文字|| a | b ||| 45.67 | cd |不要

需要这个文本

|||||||| ||||||||||||||||||这个文本


我已经尝试了一些事情的组合来得到我想要的东西,但是

不能100%得到它。 />

([\ w。] + \ * *)?,?")。Groups(1).ToString()只获取第一项,数字1
$在这种情况下b $ b。我希望文本这是我要显示的文字

而且只有那个。模式就像它在上面,前三个是

数字,然后是一些文本(我想要的文字),空,一个字母字符,

等等。


1月9日下午3:29 *,Ethan Strauss

< EthanStra ... @ discussion.microsoft.comwrote:
I will try to make it more clear.

1|2|3|this are is the text I want to display||a|b|||45.67|cd|don''t
need this text
|||||||||||||||||||||||||| this text

I''ve tried some combinations of things to get exactly what I want, but
can''t get it 100%.

([\w.]+\s*)?,?").Groups(1).ToString() only gets first item, number 1
in this case. I want the text "this are is the text I want to display"
and only that. The pattern is just like it is above, the first 3 are
digits, then some text(the text I want), empty, one alpha character,
etc in example.

On Jan 9, 3:29*pm, Ethan Strauss
<EthanStra...@discussions.microsoft.comwrote:

我不确定我是否理解这个问题,但我认为这会有所帮助。


您可以通过将其封闭来创建命名组paranethsis并添加?< name> ;.


例如,我的代码中有以下正则表达式模式

" _(?< WellName> [AH] \\d {1,2})_"


这用于捕捉Well Designation(来自AH的一封信和

,然后是一个较长的字符串中的1或2位数字,只要该图案是由下划线包围的




Regex.Match(&; SomeText_B7_MoreText", " _(小于?WellName> [AH] \\d {1,2})_")组[" * WellName"]。。值; <无线电通信/>

将返回B7 (如果我在某个地方没有错字......)

Ethan


" supercrossk ... @ gmail.com"写道:
I am not sure I understand the question, but I think this will help.

You can create a named group by enclosing it in paranethsis and add ?<name>.

For example, I have the following Regex pattern in my code
"_(?<WellName>[A-H]\\d{1,2})_"

This is used to capture just the Well Designation (a letter from A-H and
then 1 or 2 digits) from a longer string as long as that pattern is
surrounded by underscores.

Regex.Match("SomeText_B7_MoreText","_(?<WellName>[A-H]\\d{1,2})_").Groups["*WellName"].Value;

Would return "B7" (If I don''t have a typo somewhere...)
Ethan

"supercrossk...@gmail.com" wrote:

我正在尝试之前样本中的文本字符串值。

ds用于数字,s用于字符串,文本字符串用于具有多于一个或两个值的

字符串。我正在尝试使用正则表达式和

.groups方法。请帮忙。
I am trying to the values of string of text in the sample before. The
ds are for digits and s is for string and string of text is for a
string with more than one or two values. I am trying to use regex and
the .groups method. Please help.


d | d | d |文本字符串1 || s | s ||| dd.dd | ss |文本字符串

2 |||||||||||||||||||||||||||文本字符串2
d|d|d|string of text 1||s|s|||dd.dd|ss|string of text
2||||||||||||||||||||||||||string of text 2


我只需要一串text1-隐藏引用文本 -
I only want string of text1- Hide quoted text -



- 显示引用文本 -


- Show quoted text -


这篇关于正则表达式帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆