Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C# 

Regex problem

I made the following regex to grab the % from a string.
Code
string s =<tr><td colspan="4"><b>Sort tonerkassett  ~81%</b></td></tr><tr>

Regex expression = new Regex("(?=~).*(?=</b></td><)");
Match result = expression.Match(s);

I want to grab that 81 but the above regex code giving me ~81 how can grab only 81.

Thanks
This happens when you're lazy with the capture tokens! Try this pattern:
Code
(\d{1,2})%

It doesn't account for decimals though.
I would of done this:

Code
~(.*?)%

but, Odus' way is better as it shows what you're capturing would be only numbers, whereas I was kinda lazy with mine.
Thanks a lot my issue is solved i am not good in regex. :)


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C#] by HardStoNMay 9, 2019 11:22 AM 2 93 May 9, 2019 11:22 AM
Last Post: HardStoN
[C#] by i3urnApr 12, 2017 11:03 AM 4 156 Apr 12, 2017 11:03 AM
Last Post: Owl
[.NET] by WhatIsRSOct 31, 2016 07:51 PM 7 248 Oct 31, 2016 07:51 PM
Last Post: Ninja