Calculate a discount with REGEX

Hi,
I want to calculate an amount, I have the amount and I have the discount percentage,
I want to use Regex.
Is there such an expression to calculate a discount amount?
I would love an example.
Thanks

Can you share the document so that I can help you

Hello

Regex is used to capture text with a consistent pattern.

If you need to capture the discount percentage in a string like this:

Discount percentage: 18%
Total cost: $56

Once you obtain the amount you could calculate an amount sure.

As per @varunk’s post, please provide:

  • Sample
  • Expected output
  • Tell us what is consistent about the sample

You will have an answer soon after posting :smiley:

Cheers

Steve

Hi,
Yes, I try to calculate the amount after discount when I have the initial amount and I know what percentage discount there is.
I searched all the forums and found nothing,
I would be happy if you could help me with the REGEX operation
Thank you!!!

Hello again

We can’t provide a Regex pattern without a sample :blush:

If you want to learn Regex - check out my Regex MegaPost for new Users.

Cheers

Steve

Hi,
I know what REGEX is, I used it a lot to check if a variable contains letters/numbers, etc.
My question is how to use REGEX to calculate a discount.
For example:
The original amount is: $ 90
Discount is: 30%
How to do the calculation by REGEX.
It can be done in another way by:
(Original amount) * (100 / (100-discount)) Example: 0.7 * 90 then the return is the amount after discount.
Thanks

Does someone have an answer?
Thank

Hello

You might want to try using Regex to capture the discount amount THEN convert the result to an integer and then do the calculation :slight_smile:

The forum users will be happy to help you with a Regex pattern :slight_smile:

Cheers

Steve

Yes. Exactly I want it !!!

Please find the below pattern for your requirement
Discount percentage:+(.*)

Now output is 18%

  • It is in group1

@tamar.m
getting the amount:
grafik

getting the discount:
grafik

getting the reduced amount

1 Like

Thank you very much!!!
But there’s something I still do not understand,
Can you send me an example of an exercise,
How do you use it.
I always use REGEX like this: System.Text.RegularExpressions.Regex.
I would love for you to detail more to me.
Thanks!!!

@tamar.m
find starter help here:
tamar.m.xaml (5.8 KB)

ensure following:
grafik

Excellent!! It works!!!
Thank you!
I would love if you could check it out:

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.