# Function to trim Alphabets and special char except one char or special char (.) which is given as a input to function

**URL:** <https://forums.pega.com/t/function-to-trim-alphabets-and-special-char-except-one-char-or-special-char-which-is-given-as-a-input-to-function/2322>\
**Category:** User Experience\
**Tags:** java-and-activities, 8-4, user-experience\
**Created:** [March 4, 2022, 11:50am UTC](https://forums.pega.com/t/function-to-trim-alphabets-and-special-char-except-one-char-or-special-char-which-is-given-as-a-input-to-function/2322 "2022-03-04T11:50:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ramesh\_Reddy\_Battini](https://yyz2.discourse-cdn.com/pega/user_avatar/forums.pega.com/ramesh_reddy_battini/32/18530_2.png) [@Ramesh\_Reddy\_Battini](https://forums.pega.com/u/Ramesh_Reddy_Battini)\
**Post date:** [March 4, 2022, 11:50am UTC](https://forums.pega.com/t/function-to-trim-alphabets-and-special-char-except-one-char-or-special-char-which-is-given-as-a-input-to-function/2322/1 "2022-03-04T11:50:41Z")

</div>

Hello guys,

I have a requirement to trim all the aphabets and special characters except one from a user entered input. So I request you to let me know any existing function like this or help me with the java code, please.

Sample input:

123.899INR

123INR

123%

123.00%

Sample output:

123.899

123

123

123.00

So, I am a expecting a function like, it should accept the property and excluding char as inputs

Eg: @trimNonNumExcept(“.Value”, “.”)

---

<div class="post-metadata">

**Author:** ![kamic](https://yyz2.discourse-cdn.com/pega/user_avatar/forums.pega.com/kamic/32/23002_2.png) [@kamic](https://forums.pega.com/u/kamic)\
**Post date:** [March 4, 2022, 12:42pm UTC](https://forums.pega.com/t/function-to-trim-alphabets-and-special-char-except-one-char-or-special-char-which-is-given-as-a-input-to-function/2322/2 "2022-03-04T12:42:36Z")

</div>

Hi @BATTINIRAMESH,

We have the @pxReplaceAllViaRegex(String input, String regularexpression, String stringtoinsert) function available in Pega, Where it will replace all matches of a regular expression with the string to insert.

For example @pxReplaceAllViaRegex(“123.456%”,“[%]”,“”) will return 123.456 and @pxReplaceAllViaRegex(“123.456INR”,“[a-zA-Z]”,“”) will return 123.456

You can include all the special characters in the regular expression which you need to replace in the inputstring.

---

<div class="post-metadata">

**Author:** ![SaurabhG7134](https://yyz2.discourse-cdn.com/pega/user_avatar/forums.pega.com/saurabhg7134/32/17184_2.png) [@SaurabhG7134](https://forums.pega.com/u/SaurabhG7134)\
**Post date:** [March 4, 2022, 2:44pm UTC](https://forums.pega.com/t/function-to-trim-alphabets-and-special-char-except-one-char-or-special-char-which-is-given-as-a-input-to-function/2322/3 "2022-03-04T14:44:18Z")

</div>

Hi @BATTINIRAMESH, simply use this function to get your expected result:

**@pxReplaceAllViaRegex(Param.YourString,“[^1-90 \.]\*”,“”)**

Hope this helps!!

Thanks,

Saurabh.
