Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Get Numbers Before String C#

I am trying to extract numbers before string on C#. Not numbers between or after strings. Only number before string.
I need theese results.

  • dorosły ==> 0 or ""
  • dziecko 0-3 lata ==> 0 or ""
  • 1-osobowy quad ==> 1
  • 9-osobowy quad ==> 9

I tried Regex on C# but I got "";

 string test =Regex.Match("1-osobowy", @"/^(\d)-.*/m").Value;

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

try this:

string test = Regex.Match("1-osobowy", @"^\d+").Value;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading