karlenigma
08/03/2018, 11:04 AMregexp
to remove special characters and only leave me with alphanumeric characters. I am using /\W/g as the .replace
but i am getting inconsistencies when using this. Does anyone have another way or a prebuilt function to do this task?samyt
08/03/2018, 11:13 AMkarlenigma
08/03/2018, 11:39 AMjarens
08/03/2018, 12:18 PMkarlenigma
08/03/2018, 12:20 PMkarlenigma
08/03/2018, 12:47 PM-
in there.karlenigma
08/03/2018, 12:47 PMjarens
08/03/2018, 12:55 PMjarens
08/03/2018, 12:56 PMkarlenigma
08/03/2018, 12:57 PMkarlenigma
08/03/2018, 12:57 PMkarlenigma
08/03/2018, 12:58 PMkarlenigma
08/03/2018, 12:59 PMvar specialchars = /[^a-zA-Z0-9 ]/g;
if (specialchars.test(opn)) {
var altOPN = opn.replace(/[^a-zA-Z0-9 ]/g, '');
}
karlenigma
08/03/2018, 12:59 PMjarens
08/03/2018, 1:00 PMkarlenigma
08/03/2018, 1:00 PMkarlenigma
08/03/2018, 1:00 PMsamyt
08/03/2018, 1:02 PMkarlenigma
08/03/2018, 1:02 PMkarlenigma
08/03/2018, 1:02 PMsamyt
08/03/2018, 1:02 PMsamyt
08/03/2018, 1:03 PMkarlenigma
08/03/2018, 1:03 PMsamyt
08/03/2018, 1:05 PMkarlenigma
08/03/2018, 1:12 PMkarlenigma
08/03/2018, 1:13 PMsamyt
08/03/2018, 1:16 PMkarlenigma
08/03/2018, 1:19 PMsamyt
08/03/2018, 1:20 PMkarlenigma
08/03/2018, 1:20 PMkarlenigma
08/03/2018, 1:20 PMsamyt
08/03/2018, 1:21 PMkarlenigma
08/03/2018, 1:22 PMkarlenigma
08/03/2018, 1:23 PMsamyt
08/03/2018, 1:23 PMsamyt
08/03/2018, 1:24 PMkarlenigma
08/03/2018, 1:24 PMsamyt
08/03/2018, 1:29 PMkarlenigma
08/03/2018, 1:36 PMvar opn = contextobject.values["GROUP(name)"]; // OPN value from Old OPN Record
var altOPN = opn.replace(/[^a-zA-Z0-9]/g, ''); // OPN value without any special characters
if (opn === altOPN) {
altOPN = '';
}
samyt
08/03/2018, 1:41 PMkarlenigma
08/03/2018, 1:41 PMsamyt
08/03/2018, 1:44 PMjkabot
08/03/2018, 4:26 PMg
flag at the end of your regular expression. The g
flag is for repeatedly testing the same string with the same regular expression.jkabot
08/03/2018, 4:36 PMg
flag it changes the internal state of the regular expression object.
The Rhino engine that runs your javascript on the server has an """optimization""" that reuses a regular expression object when you declare a new one with the same pattern. So even though you have a "new" /[^a-zA-Z0-9]/g
, it is using the same internal state as the last time you used /[^a-zA-Z0-9]/g
.
This is different behavior than you'll see in your browser.karlenigma
08/03/2018, 4:51 PMjkabot
08/03/2018, 4:51 PMg
flag.
It's for testing the same string with the same regexp, which it doesn't seem like you're doing.karlenigma
08/03/2018, 4:54 PMsamyt
08/03/2018, 5:08 PM