- Home /
 
 
               Question by 
               AndreasX12 · Sep 02, 2014 at 09:35 AM · 
                findregexextract  
              
 
              Find text with regex
Hi. I don't understand the pattern in regex. What should I do to get: 12.411 m² from this string?:
 <div class="s20 red">68.000.000 kr.</div>
 <div class="remem">
 <input type="checkbox" id="chkRemember_d6b706eaeb544dd6a319bc9d64db7f4e"/>
 <label for="chkRemember_d6b706eaeb544dd6a319bc9d64db7f4e" class="gray bold s11 upper">Husk</label></div>
 </div>
 </div>
 <div class="kf3 tip-white" title="Antal kvadratmeter grund (mæglerens registrering)"><span>Grund</span>12.411 m²</div>
 
               This is my current code which I got from another answer. string pattern = @"[1-9]{1}\d{0,2}.?(\d{1,3}.?)*\skr."; 
 Regex regex = new Regex(pattern, RegexOptions.None); Match m = regex.Match(data); 
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by Landern · Sep 04, 2014 at 07:51 PM
 NODE                     EXPLANATION
 --------------------------------------------------------------------------------
   [1-9]{1}                 any character of: '1' to '9' (1 times)
 --------------------------------------------------------------------------------
   \d{0,2}                  digits (0-9) (between 0 and 2 times
                            (matching the most amount possible))
 --------------------------------------------------------------------------------
   .?                       any character except \n (optional
                            (matching the most amount possible))
 --------------------------------------------------------------------------------
   (                        group and capture to \1 (0 or more times
                            (matching the most amount possible)):
 --------------------------------------------------------------------------------
     \d{1,3}                  digits (0-9) (between 1 and 3 times
                              (matching the most amount possible))
 --------------------------------------------------------------------------------
     .?                       any character except \n (optional
                              (matching the most amount possible))
 --------------------------------------------------------------------------------
   )*                       end of \1 (NOTE: because you are using a
                            quantifier on this capture, only the LAST
                            repetition of the captured pattern will be
                            stored in \1)
 --------------------------------------------------------------------------------
   \s                       whitespace (\n, \r, \t, \f, and " ")
 --------------------------------------------------------------------------------
   kr                       'kr'
 --------------------------------------------------------------------------------
   .                        any character except \n
 
              Wow, I would have just posted a link to the Regex wiki ;)
And here's a useful link to actually test your regex
Thanks for your answer, Landern. Let's say I have a string "23.532 meters". Is there a way to 'tell' regex to take everything after and before ?
Best regards.
Sure, use lookarounds:
http://www.rexegg.com/regex-lookarounds.html Test your expressions here: http://regex101.com/
Your answer