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

C# 

C# Regex match 2 patterns?

Having a bit of trouble matching 2 patterns.

Here is the current pattern it is matching.
public static string pattern = @"EUR \d{2,3}\,\d{2}";

If anyone can help me, I would appreciate it a lot!
[Image: L9unCFX.png]
What pattern is it matching? Or am I missing something?
(Jan 29, 2017 07:47 PM)Annabelle Lee Wrote:  What pattern is it matching? Or am I missing something?

Fuck I'm stupid. I've updated the OP.
[Image: L9unCFX.png]
(Jan 29, 2017 07:50 PM)Priology Wrote:  Fuck I'm stupid. I've updated the OP.

I meant that's the regex, but what are you trying to match it against? Sample text?
Your pattern looks fine but if you want to capture the match you must mark a group: EUR (\d{2,3}\,\d{2})
(Jan 30, 2017 04:57 AM)Owl Wrote:  Your pattern looks fine but if you want to capture the match you must mark a group: EUR (\d{2,3}\,\d{2})

He wants both tho?
wouldent it be
Code
EUR (\d{2,3})\,(\d{2})
Lotta blood to let, peace to make, give a fuk about a check
(Jan 30, 2017 05:31 AM)BahNahNah Wrote:  He wants both tho?
wouldent it be
Code
EUR (\d{2,3})\,(\d{2})

I would say this is correct, but why isn't he parsing it as a double to easily use it to round/cut down to x decimal places...
Mmh, strange either way.
[Image: PVoDiqS.png]
(Jan 29, 2017 07:37 PM)Priology Wrote:  Having a bit of trouble matching 2 patterns.

Here is the current pattern it is matching.
public static string pattern = @"EUR \d{2,3}\,\d{2}";

If anyone can help me, I would appreciate it a lot!

On the side, why are you using Regex in the first place ?
Are you not just trying to see if its a valid Euro amount aka a decimal one or looking for the string "Eur" and the format ?

Regex is more heavy than a 'TryParse' & Contains("Eur").


EDIT:
To be more complete here are samples on how you could do it (assuming im not mistaking on what you want to achieve ofc)

Get the current threads UI culture and display its currency (USD, EUR, ...)
PHP Code

<?php 
RegionInfo ri 
= new RegionInfo(System.Threading.Thread.CurrentThread.CurrentUICulture.LCID);
            
Console.WriteLine(ri.ISOCurrencySymbol); 

Same as above
PHP Code

<?php 
string ci 
= CultureInfo.CurrentCulture.NumberFormat.CurrencySymbol;
            
Console.WriteLine(ri.ISOCurrencySymbol); 

Try parse your value to a decimal one
PHP Code

<?php 
// check if "input" contains "Eur" before trying to parse it.
string input;
decimal output;
            if (
decimal.TryParse(input, NumberStyles.Number | NumberStyles.AllowCurrencySymbol, CultureInfo.CurrentCulture, out output))
            {
               
// continue here  
            
} 

🤝
(Jan 30, 2017 05:31 AM)BahNahNah Wrote:  He wants both tho?
wouldent it be
Code
EUR (\d{2,3})\,(\d{2})

As LaPanthere said, I also found it strange to capture the decimal's sides individually. He could also mean there are 2 potential matches.

If that is not the case then yes it would be
(Jan 30, 2017 04:57 AM)Owl Wrote:  Your pattern looks fine but if you want to capture the match you must mark a group: EUR (\d{2,3}\,\d{2})

(Jan 30, 2017 05:31 AM)BahNahNah Wrote:  He wants both tho?
wouldent it be
Code
EUR (\d{2,3})\,(\d{2})

(Jan 30, 2017 06:37 AM)Cecilia Wrote:  I would say this is correct, but why isn't he parsing it as a double to easily use it to round/cut down to x decimal places...
Mmh, strange either way.

(Jan 30, 2017 09:01 AM)Owl Wrote:  As LaPanthere said, I also found it strange to capture the decimal's sides individually. He could also mean there are 2 potential matches.

If that is not the case then yes it would be

I'm not experienced with C#, I apologise.

I'm trying to scrape prices from a website,
the format is like this:
"EUR 00,00" || "EUR 000,00" || "EUR 0.000,00"
However, I'm also trying to scrape the names of the items, so I need to match other strings.
[Image: L9unCFX.png]


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Python] by Hello BuddyDec 11, 2017 11:36 PM 2 171 Dec 11, 2017 11:36 PM
Last Post: klorox
[Java] by ғlαѕнpoιɴтJan 13, 2017 09:41 PM 14 467 Jan 13, 2017 09:41 PM
Last Post: ASLR
[.NET] by Whateva_Sep 5, 2016 12:20 PM 1 121 Sep 5, 2016 12:20 PM
Last Post: Chickendipper