# Using regular expressions in ReplaceAll function

**URL:** <https://forum.katalon.com/t/using-regular-expressions-in-replaceall-function/60766>\
**Category:** Web Testing\
**Tags:** katalon-studio\
**Created:** [December 11, 2021, 4:42pm UTC](https://forum.katalon.com/t/using-regular-expressions-in-replaceall-function/60766 "2021-12-11T16:42:25Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![pasthana](https://avatars.discourse-cdn.com/v4/letter/p/c77e96/32.png) [@pasthana](https://forum.katalon.com/u/pasthana)\
**Post date:** [December 11, 2021, 4:42pm UTC](https://forum.katalon.com/t/using-regular-expressions-in-replaceall-function/60766/1 "2021-12-11T16:42:25Z")

</div>

Hello

I am trying to use replaceAll function to replace a text string in my application.  
I retrieve ‘Quantity on hand’ from my app which is a string into a variable QtyOnHand  
QtyOnHand = ‘200.00’  
Then I want to replace it with a string ‘10000’  
Using replaceAll function, as below  
QtyToReplace = QtyOnHand.replaceAll(‘\*.00’,‘10000’)  
println('QuantitytoReplace = ’ + QtyToReplace)  
Get errors. What is the correct regular expression to use in this case?

 ![image](https://europe1.discourse-cdn.com/katalon/original/3X/f/e/fe59e6f5468c9fdfb39124047fa2ad2085475825.png)

Appreciate any help I can get.

Thanks

---

<div class="post-metadata">

**Author:** ![pasthana](https://avatars.discourse-cdn.com/v4/letter/p/c77e96/32.png) [@pasthana](https://forum.katalon.com/u/pasthana)\
**Post date:** [December 11, 2021, 6:01pm UTC](https://forum.katalon.com/t/using-regular-expressions-in-replaceall-function/60766/2 "2021-12-11T18:01:29Z")

</div>

Wanted to do it with a settext function. Not allowing me to enter a number 10000.  
WebUI.setText(findTestObject(‘Poonam/input\_QuantityonHand’), ‘800.00’)

 ![image](https://europe1.discourse-cdn.com/katalon/original/3X/3/e/3ea8ce09bdd8a03d8cc879182b18953f561638f2.png)

---

<div class="post-metadata">

**Author:** ![grylion54](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/grylion54/32/16265_2.png) [@grylion54](https://forum.katalon.com/u/grylion54)\
**Post date:** [December 11, 2021, 6:47pm UTC](https://forum.katalon.com/t/using-regular-expressions-in-replaceall-function/60766/3 "2021-12-11T18:47:49Z")

</div>

The heading is “Quantity on hand” and I would think it would want **only** an **integer** value–without decimal point–as you would only want complete/whole products, no partials. Should you be allowed to enter a decimal number?

Anyways, how about:

```auto
WebUI.clearText(findTestObject('Poonam/input_QuantityonHand'))
WebUI.setText(findTestObject('Poonam/input_QuantityonHand'), '800.00')

```

---

<div class="post-metadata">

**Author:** ![pasthana](https://avatars.discourse-cdn.com/v4/letter/p/c77e96/32.png) [@pasthana](https://forum.katalon.com/u/pasthana)\
**Post date:** [December 11, 2021, 8:20pm UTC](https://forum.katalon.com/t/using-regular-expressions-in-replaceall-function/60766/4 "2021-12-11T20:20:37Z")

</div>

Thanks for your reply. I tried cleartext. It clears the text but then does not set the text correctly and appends to the 0.00. Looks like a problem in the application. When I run a recorded script, it used settext to enter the value with a decimal point, and there were no issues. I use the same statement and it gives me erros. Screenshots below of cleartext being used and then settext to set the value

 ![image](https://europe1.discourse-cdn.com/katalon/original/3X/0/f/0f2e0f0231d1608d59c39d3dc1371684bd417aed.png)

In the code  
if (QtyOnHand\_Actual \<= 500) {  
//If QtyOnHand \< 500 make it 10000  
WebUI.clearText(findTestObject(‘Poonam/input\_QuantityonHand’))  
WebUI.setText(findTestObject(‘Poonam/input\_QuantityonHand’), ‘10000’)  
[//WebUI.sendKeys](https://WebUI.sendKeys)(findTestObject(‘Object Repository/Poonam/input\_Quantity on Hand\_quantity\_on\_hand’), ‘800.00’)  
[//WebUI.delay](https://WebUI.delay)(5)  
QtyOnHandAfterInvAdded = WebUI.getAttribute( (findTestObject(‘Poonam/input\_QuantityonHand’)), “value” )  
println('Quantity On Hand After Inventory added= ’ + QtyOnHandAfterInvAdded)  
WebUI.click(findTestObject(‘Poonam/input\_btnSAVE’) )  
}  
}

---

<div class="post-metadata">

**Author:** ![pasthana](https://avatars.discourse-cdn.com/v4/letter/p/c77e96/32.png) [@pasthana](https://forum.katalon.com/u/pasthana)\
**Post date:** [December 11, 2021, 8:24pm UTC](https://forum.katalon.com/t/using-regular-expressions-in-replaceall-function/60766/5 "2021-12-11T20:24:52Z")

</div>

Script below which Katalon recorded with decimal value and using settext. Running this script has no issues in setting the value to 800.00

WebUI.setText(findTestObject(‘Object Repository/PoonamTwo/input\_Quantity on Hand\_quantity\_on\_hand’), ‘800.00’)

WebUI.click(findTestObject(‘Object Repository/PoonamTwo/input\_Defines the Available quantity to dis\_09d21d’))

 ![image](https://europe1.discourse-cdn.com/katalon/original/3X/c/d/cd8265d755c5533e2e6fc7060a66bddb7c9e9351.png)

---

<div class="post-metadata">

**Author:** ![Dave\_Evers](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/dave_evers/32/435_2.png) [@Dave\_Evers](https://forum.katalon.com/u/Dave_Evers)\
**Post date:** [December 11, 2021, 9:41pm UTC](https://forum.katalon.com/t/using-regular-expressions-in-replaceall-function/60766/6 "2021-12-11T21:41:05Z")

</div>

Hi @pasthana, try the following:

```auto
WebUI.enhancedClick(findTestObject(‘Poonam/input_Quantity on Hand_quantity_on_hand’))
WebUI.clearText(findTestObject(‘Poonam/input_Quantity on Hand_quantity_on_hand’))
WebUI.sendKeys(findTestObject(‘Poonam/input_Quantity on Hand_quantity_on_hand’), ‘800.00’)

```

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [December 12, 2021, 2:32am UTC](https://forum.katalon.com/t/using-regular-expressions-in-replaceall-function/60766/7 "2021-12-12T02:32:46Z")

</div>

@pasthana

Please use “Code Formatting” markdown syntax to preset your codes better readable.

 ![code formatting](https://europe1.discourse-cdn.com/katalon/original/3X/3/f/3f0611012346e0c9ee9918c00cfc288c38b29653.png)

---

<div class="post-metadata">

**Author:** ![Russ\_Thomas](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/russ_thomas/32/11884_2.png) [@Russ\_Thomas](https://forum.katalon.com/u/Russ_Thomas)\
**Post date:** [December 13, 2021, 12:36pm UTC](https://forum.katalon.com/t/using-regular-expressions-in-replaceall-function/60766/8 "2021-12-13T12:36:08Z")

</div>

There is a common confusion running through this thread: **the mixing up of string values and numeric values**.

Most WebUI APIs (e.g.`setText`) deal with **string values**.

@pasthana please make sure YOU are clear about what is a string and what is a numeric value. For example:

> [@pasthana](#):
>
> Script below which Katalon recorded with decimal value

No, it didn’t. It recorded a _string_, `"800.00"` which is not a decimal value.

> [@pasthana](#):
>
> Running this script has no issues in setting the value to 800.00
> 
> WebUI.setText(findTestObject(‘Object Repository/PoonamTwo/input\_Quantity on Hand\_quantity\_on\_hand’), ‘800.00’)

You did not set the value `800.00`, you set the value `'800.00'` – again, _a string_.

Going back to your OP, I see no reason why you need to use a regular expression.

Can you please post back with a clear statement as to what you want to achieve and the current status of your test case. Thanks.

---

<div class="post-metadata">

**Author:** ![pasthana](https://avatars.discourse-cdn.com/v4/letter/p/c77e96/32.png) [@pasthana](https://forum.katalon.com/u/pasthana)\
**Post date:** [December 13, 2021, 3:21pm UTC](https://forum.katalon.com/t/using-regular-expressions-in-replaceall-function/60766/9 "2021-12-13T15:21:03Z")

</div>

Thanks a ton Dave. The enhancedClick, clearText and sendKeys methods worked like a charm. My string got set to ‘800.00’ as I had wanted.

 ![image](https://europe1.discourse-cdn.com/katalon/original/3X/4/c/4cd587d3ba9c167edf8dd83733087305b9b7b72e.png)

---

<div class="post-metadata">

**Author:** ![pasthana](https://avatars.discourse-cdn.com/v4/letter/p/c77e96/32.png) [@pasthana](https://forum.katalon.com/u/pasthana)\
**Post date:** [December 13, 2021, 3:29pm UTC](https://forum.katalon.com/t/using-regular-expressions-in-replaceall-function/60766/10 "2021-12-13T15:29:05Z")

</div>

Hi Russ

My statement was a bit unclear when I said Katalon recorded with decimal value and settext. I had meant to say Katalon recorded the string ‘800.00’ using setText method. I had wanted a string there. Whereas in my code when I had wanted to compare that string value to a numeric I had converted that string to a numeric and compared it to a number I wanted. Using Dave’s solution posted here using enhancedClick, clearText and sendKeys to send the string ‘800.00’ worked. Appreciate your reply! Thanks

---

<div class="post-metadata">

**Author:** ![Russ\_Thomas](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/russ_thomas/32/11884_2.png) [@Russ\_Thomas](https://forum.katalon.com/u/Russ_Thomas)\
**Post date:** [December 13, 2021, 4:51pm UTC](https://forum.katalon.com/t/using-regular-expressions-in-replaceall-function/60766/11 "2021-12-13T16:51:48Z")

</div>

Closed on December 13, 2021, 4:51pm UTC


