The CreatorCon Call for Content is officially open! Get started here.

Script function to remove symbol characters from string field

leahdany
Giga Guru

In the Citations table, citation names sometimes contain characters/symbols that are unreadable by JavaScript and it's causing my script that works otherwise not to work. To test this I would copy a query from the citation table where the name had a special character/symbol in it - something like this query 'name=Annex A: § CLD.12.1.5 Table: Cloud service provider' - and I would only query for those citations in my GlideRecord query. It would return a row count of zero. If I modified the query where name ends with 'CLD.12.1.5 Table: Cloud service provider' it would find the two records.

I've looked up the trim function but I don't think that will work here. I need a way to remove the characters/symbols that JavaScript cannot read.

Some examples of these characters are the paragraph symbol shown here:

find_real_file.png

And whatever this symbol is shown here:

find_real_file.png

 

1 ACCEPTED SOLUTION

Elijah Aromola
Mega Sage

You could write a regular expression that filters out any thing that isn't a letter, number or period. 

var regex = /[^A-Za-z0-9\.]/
var name = gr.name
name.replace(regex, "")

 

This would replace any character that isn't a letter, number or period with "".

View solution in original post

4 REPLIES 4

Elijah Aromola
Mega Sage

You could write a regular expression that filters out any thing that isn't a letter, number or period. 

var regex = /[^A-Za-z0-9\.]/
var name = gr.name
name.replace(regex, "")

 

This would replace any character that isn't a letter, number or period with "".

Thanks! If I need to keep any other characters like parentheses would I add them in the regular expression after the period?

Correct you'd also have to escape it with a backslash.

Like this? var regex = /[^A-Za-z0-9\.()\]/ Or this? var regex = /[^A-Za-z0-9\.\()]/