模式匹配 [英] Pattern Match

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

问题描述

我不是模式匹配方面的专家,我需要一段时间才能用我想要做的语法来提出



我希望有一些专家可以帮助我。


我试图在任何文本中匹配/ d / d / d / s / d / d。


在模式前面或后面可能有空格(nnn nn可能是没有空格的
)但是如果这样的情况下它不应该拾取它


1234 56768

以上图案会给我234 56.


如果我这样做/ s / d / d / d / s / d / d / s

然后我必须在前面和后面留有空格,但事实并非如此。


Konrad。

解决方案

9月7日上午11点16分,konrad Krupa < kon ... @ commandtech.comwrote:


我不是模式匹配专家,我需要一段时间才能上来

,其中包含我正在尝试做的语法。

我希望有一些专家可以帮助我。


我'尝试在任何文本中匹配/ d / d / d / s / d / d。

模式前面或后面可能有空格(nnn nn可能

也没有空格)但它不应该在这样的情况下捡起来


1234 56768


以上模式会给我234 56.


如果我这样做/ s / d / d / d / s / d / d / s

那么我必须在前面和后面都有空格,但事实并非如此。


康拉德。



怎么样怎么样

[^ \d] \d {3} \s + \d {2}


(非数字后跟3位数后跟一个或多个空格

后跟2位数)


9月7日上午11:33,Doug Semler< dougsem ... @ gmail.comwrote:


9月7日,11:16 am,konrad Krupa < kon ... @ commandtech.comwrote:



我不是模式匹配的专家,它会带我一个然后用我想要做的语法来表示



我希望有一些专家可以帮助我。


我试图在任何文本中匹配/ d / d / d / s / d / d。


模式前面或后面可能有空格(nnn nn可能是

也没有空格)但是它在这样的情况下不应该捡到这个


1234 56768


以上模式会给我234 56.


如果我这样做/ s / d / d / d / s / d / d / s

然后我必须在前面和之后有空格,但实际情况并非如此。


Konrad。



怎么样比如

[^ \d] \d {3} \s + \d {2}


(非数字后跟3位数后跟一个或多个空格

后跟2位数)



PS如果你只想获得数字匹配,你会想要通过将它粘贴到一个catpuring组中来捕获

,如下所示:


[ ^ \d](\d {3} \s + \d {2})


感谢您提示。


您建议的模式修复问题12345 6789

但是我仍然需要匹配只有123 45的字符串
>
有没有办法让它们以一种模式出现?

Konrad。

" Doug Semler" < do ******** @ gmail.comwrote in message

news:11 ********************** @ r29g2000hsg.googlegr oups.com ...


9月7日上午11点33分,Doug Semler< dougsem ... @ gmail.comwrote:


> 9月7日上午11点16分,konrad Krupa < kon ... @ commandtech.comwrote:



我不是模式匹配的专家,它会带我一个来吧

up

,我正在尝试做的语法。

我希望有一些专家可以提供帮助我。


我试图在任何文本中匹配/ d / d / d / s / d / d。


模式前面或后面可能有空格(nnn nn可以



没有空格也)但是它不应该在这样的情况下拿起来


1234 56768

< blockquote class =post_quotes>
以上模式会给我234 56.


如果我这样做/ s / d / d / d / s / d / d / s

然后我必须在前面和之后有空格,这不是

的情况。


Konrad。


如何使用
[^ \d] \d {3} \ s + \d {2}

数字后跟3位数后跟一个或多个空格
后跟2位数字)



PS如果你只想获得数字匹配,你会想要通过将它粘贴到一个catpuring组中来捕获

,如下所示:


[ ^ \d](\d {3} \s + \d {2})



I''m not expert in Pattern Matching and it would take me a while to come up
with the syntax for what I''m trying to do.
I hope there are some experts that can help me.

I''m trying to match /d/d/d/s/d/d in any text.

There could be spaces in front or after the pattern (the nnn nn could be
without spaces also) but it shouldn''t pick it up in case like this

1234 56768

above pattern would give me 234 56.

If I do this /s/d/d/d/s/d/d/s
then I have to have spaces in front and after it, which is not the case.

Konrad.

解决方案

On Sep 7, 11:16 am, "konrad Krupa" <kon...@commandtech.comwrote:

I''m not expert in Pattern Matching and it would take me a while to come up
with the syntax for what I''m trying to do.
I hope there are some experts that can help me.

I''m trying to match /d/d/d/s/d/d in any text.

There could be spaces in front or after the pattern (the nnn nn could be
without spaces also) but it shouldn''t pick it up in case like this

1234 56768

above pattern would give me 234 56.

If I do this /s/d/d/d/s/d/d/s
then I have to have spaces in front and after it, which is not the case.

Konrad.

howbout something like
[^\d]\d{3}\s+\d{2}

(Non digit followed by 3 digits followed by one or more whitespace
followed by 2 digits)


On Sep 7, 11:33 am, Doug Semler <dougsem...@gmail.comwrote:

On Sep 7, 11:16 am, "konrad Krupa" <kon...@commandtech.comwrote:


I''m not expert in Pattern Matching and it would take me a while to come up
with the syntax for what I''m trying to do.
I hope there are some experts that can help me.

I''m trying to match /d/d/d/s/d/d in any text.

There could be spaces in front or after the pattern (the nnn nn could be
without spaces also) but it shouldn''t pick it up in case like this

1234 56768

above pattern would give me 234 56.

If I do this /s/d/d/d/s/d/d/s
then I have to have spaces in front and after it, which is not the case.

Konrad.


howbout something like
[^\d]\d{3}\s+\d{2}

(Non digit followed by 3 digits followed by one or more whitespace
followed by 2 digits)

P.S. If you want to get only the digit match, you''ll want to capture
it by sticking it into a catpuring group, like this:

[^\d](\d{3}\s+\d{2})


Thank you for the tip.

The pattern you suggested fixes problem 12345 6789

but I still need to get match on string that has only 123 45

Is there any way to get them in one pattern?
Konrad.
"Doug Semler" <do********@gmail.comwrote in message
news:11**********************@r29g2000hsg.googlegr oups.com...

On Sep 7, 11:33 am, Doug Semler <dougsem...@gmail.comwrote:

>On Sep 7, 11:16 am, "konrad Krupa" <kon...@commandtech.comwrote:


I''m not expert in Pattern Matching and it would take me a while to come
up
with the syntax for what I''m trying to do.
I hope there are some experts that can help me.

I''m trying to match /d/d/d/s/d/d in any text.

There could be spaces in front or after the pattern (the nnn nn could
be
without spaces also) but it shouldn''t pick it up in case like this

1234 56768

above pattern would give me 234 56.

If I do this /s/d/d/d/s/d/d/s
then I have to have spaces in front and after it, which is not the
case.

Konrad.


howbout something like
[^\d]\d{3}\s+\d{2}

(Non digit followed by 3 digits followed by one or more whitespace
followed by 2 digits)


P.S. If you want to get only the digit match, you''ll want to capture
it by sticking it into a catpuring group, like this:

[^\d](\d{3}\s+\d{2})



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

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