Need regex to find number or decimal in text

Hi Team,

I am getting amount in text in below format. I need a regex to validate it’s number or decimal in text.

Amount example:

403, 403.00, 403.18, u03.18, u03

BOT should give false value if we check amount u03.18 and u03 and give true value if we check 403, 403.00 and 403.18

Can anyone pleas help in making regex ?

Thanks in Advance.

Regards,
Deepak

Hi @Deepak_Chawla

You can use the below one,

System.Text.RegularExpressions.Regex.Ismatch(Input,"(?<=\s*)[A-Za-z]\d+\.?\d*")

The above condition checks these values u03.18 and u03 if it is like this then bot went to then block assign the boolean as false. If the values are this 403, 403.00 and 403.18 then bot went to else assign the boolean as True.

Check the below workflow for u03.18 value, it was giving false as output,

Check the below workflow for 403.00 value, it was giving true as output,

Hope it helps!!

Hey @Deepak_Chawla
try this:
^\d{1,3}(,\d{3})*(\.\d+)?$
or
System.Text.RegularExpressions.Regex.IsMatch(inputString, @"^\d+(\.\d{1,2})?$")

You can simply do it in single assign activity by below expression… @Deepak_Chawla

- Assign -> Input = "403.00"

- Assign -> Bool_Flag (Boolean Datatype) = If(System.Text.RegularExpressions.Regex.Ismatch(Input,"(?<=\s*)[A-Za-z]\d+\.?\d*"),False,True)

Check the below workflow,

Hope it helps!!

amount can be on “n” digit

it is giving false for “40301.012”

It was giving True for me please check the below workflow,

Could you confirm with that where you have assigned True value in Then block or else block

Hope you understand!!

Is matching activity gave me false value. i want to use regex in UiPath forum. will it work ?

No I have written regex for these u03.18, u03.

→ If this matches then it will go to then block in then block assign the boolean as True.
→ If this doesn’t match then it will go to else block in else block assign the boolean as False.

If you have any doubt by using If condition simply use the below expression in assign activity,

- Assign -> Bool_Flag (Boolean Datatype) = If(System.Text.RegularExpressions.Regex.Ismatch(Input,"(?<=\s*)[A-Za-z]\d+\.?\d*"),False,True)

Hope you understand!!

I have to use above regex in UiPath forum and check if amount is correct then user should submit. i think it won’t work because it will check for char value.

could you please write for amount because i am checking for correct amount ( number and decimal )?

Hi @Deepak_Chawla

Use this :

System.Text.RegularExpressions.Regex.IsMatch(Result, @“^(?=.\d)\d{1,3}(,\d{3})(.\d+)?$”)

Thank you!

@Deepak_Chawla

Use this Regex:

System.Text.RegularExpressions.Regex.IsMatch(Result, @“^\d+(.\d{1,2})?$”)

Cheers…!

Thanks for your help!

I got my answer we have to use same regex in UiPath forum because we are checking for incorrect amount. It is working fine and giving True for “u” but when we are searching any special character like “/403.330”, “<403.00” it is giving false. it should give true because amount is in incorrect format.

where should we update in regex ?

Give me some inputs of amounts how it was… @Deepak_Chawla

Then I’ll write the regular expressions for it.

when I am searching “a403.12”, “4u03.67” it is giving true because we are searching char value and giving false for “403.45”, "40345.678 because amount is correct as per regex

when I am searching any special character instead of char like “@403.00”, “%456.78” it is giving me false. it should give me true because we are searching for in correct amount.

can you please update regex for special character because it is rejecting amount if amount contains char ?

Change the below regex and try,

(?<=\s*)([A-Za-z]|\%|\@)\d+\.?\d*

Hope you understand!!

1 Like

Working fine, Thanks for your help

It’s my pleasure… @Deepak_Chawla

Happy Automation!!

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