寻找一些C#正则表达式的帮助 [英] Seeking some C# RegEx help

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

问题描述

我想创建一个正则表达式表达式将成功地解析以下行:

I am trying to create a RegEx expression that will successfully parse the following line:

"57" "testing123" 82 16 # 13 26 blah blah

我要的是能够做的是确定的数字线。目前,有什么我使用是这样的:

What I want is to be able to do is identify the numbers in the line. Currently, what I'm using is this:

[0-9]+

它解析罚款。但是,如果它得到棘手的是,如果该号码是在引号,像57或者是像是testing123是的,我不希望它来搭配。

which parses fine. However, where it gets tricky is if the number is in quotes, like "57" is or like "testing123" is, I do not want it to match.

除此之外,井号(以下简称#)后的任何事情,我不想井号后面的所有匹配任何东西。

In addition to that, anything after the hash sign (the '#"), I do not want to match anything at all after the hash sign.

因此,在本例中,我应该得到的匹配是82和16。没有别的应匹配

So in this example, the matches I should be getting are "82" and "16". Nothing else should match.

任何帮助,将不胜感激。

Any help on this would be appreciated.

推荐答案

它应该是更容易为你打造3个不同的正则表达式,然后创建结合他们的逻辑:

It should be easier for you to build 3 different regexes, and then create the logic that combines them:


  1. 检查,该字符串是否有#,和之后不顾一切

  2. <李>检查,为\d +所有的比赛,而忽略所有<中/ LI>
  3. 检查剩下的一切,无论是匹配[0-9] +

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

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