Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
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&#230;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
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
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
Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image jokim · Sep 04, 2014 at 08:07 PM 0
Share

Wow, I would have just posted a link to the Regex wiki ;)

And here's a useful link to actually test your regex

avatar image AndreasX12 · Sep 04, 2014 at 08:58 PM 0
Share

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.

avatar image Landern · Sep 05, 2014 at 01:26 PM 1
Share

Sure, use lookarounds:

http://www.rexegg.com/regex-lookarounds.html Test your expressions here: http://regex101.com/

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

23 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

find object in game view 1 Answer

How do I instantiate same tag/name GameObjects with an array 1 Answer

Finding the polygon/face your'e currently looking at? 2 Answers

GetComponent usage returns NullReferenceException, not sure why 1 Answer

How can I check if a GameObject has a Mesh? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges