c# - How to extract numbers from a string using regular expressions? -


This small challenge only screams regular expressions for me, but I'm still stumped.

I have an arbitrary string in which it contains two numbers, I need to remove those two numbers, which are n and m marks long (n, m are unknown in advance). The format of the string is always

  fixed word [nnnn] second fixword [mnn] altmorstfontththand  

The first number is of format <.> 1.2.3.4 < / Code> (Number of digits vary) such as 5.3.20 or 5.3.10.1 or 5.4 .

And another simple 'M' digit (like 25 or 2 )

For example "AppName5 .2.6dbVer44Oracle.Group "

This does the" pattern mailing "and therefore" can be used to clear the regexes "can someone guide me further?

TIA

The following pattern:

  (\ d + (? & Gt; \. \ D +) *) w + + (+ d +)  

will match Do:

  AppName5.2.6dbVer44Oracle.Group \ __________ / & lt; - Match \ ___ / \ / & lt; - Capture  

and capture captures that you are interested in capturing groups.

Use it like this:

  var match = regesx. Match (input, @ "(\ d + (? & Gt; \. \ D +) *) \ w +? (\ D +)"); If (match.Success) {var first = match.Groups [1] value; Var second = match Group [2]. value; // ...}  

Pattern details:

  (# group 1 launches \ d + # A series of series (? & Gt; begin the atomic group. \ D + # dot after digits) * #. 0 to n times) \ w +? # A series of digits captured in some word characters (as low as possible) (\ d +) # group 2  

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -