cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Wildcard string replacement ?

dunncrew
Deputy Chef III
Deputy Chef III

Hi, is there a way to replace characters using a wildcard  with a blank ?

There are always 6 zeroes, and random 3 digits and a period before the 6 zeroes

2023-10-09 17:38:36.243000000   More text here                                                                    

2023-10-09 17:42:37.770000000   More text here 

Becomes

2023-10-09 17:38:36  More text here                                                                    

2023-10-09 17:42:37   More text here 

 

1 ACCEPTED SOLUTION

gary1
Executive Chef III
Executive Chef III

Hi, me again. You can use gsub with a regular expression (regex).

The below regex looks for a period followed by any quantity of numbers and removes them.

[message].gsub(/[.][0-9]+/,"")

Example: "2023-10-09 17:38:36.243000000" becomes "2023-09 17:38:36"

There are a million regex sites out there but I find this one particularly helpful: https://regexr.com/

View solution in original post

3 REPLIES 3

gary1
Executive Chef III
Executive Chef III

Hi, me again. You can use gsub with a regular expression (regex).

The below regex looks for a period followed by any quantity of numbers and removes them.

[message].gsub(/[.][0-9]+/,"")

Example: "2023-10-09 17:38:36.243000000" becomes "2023-09 17:38:36"

There are a million regex sites out there but I find this one particularly helpful: https://regexr.com/

dunncrew
Deputy Chef III
Deputy Chef III

Thanks. I will add that to my "Tips & Tricks" document I am making for myself.

hilda-o
Deputy Chef I
Deputy Chef I

Hi, 

following up on this conversation. What if i want to replace spaces, commas, periods, etc from the string to an empty string. What should I provide in the find regex value?

Ex: string = abc, def inc. 

output should be abcdefinc

<string>.gsub(?,'')

Thank you for your help! 

Hilda.