Removing unwanted characters from string using javascript regex for feeding into MYSQL statement -


hi need remove unwanted characters string, i'm trying make regex match required characters feel i'm miles off , don't want create false positives. appreciated.

the starting string looks like:

'select \t* \nfrom \taudit_log changedate > \'2016-07-21t18:51:41.900z\'' 

however doesn't parsed correctly mysql, needs like:

'select * \taudit_log changedate > '2016-07-21t18:51:41.900z'' 

i've tried not having luck:

str = str.replace('\t', ''); str = str.replace('\n', ''); str = str.replace('\\', ''); 

if escape plus a-z culprit, simplify 2 cases:

  1. escape + not a-z nor escape
  2. escape + a-z or escape

in first case, not a-z (punctuation) written back.
in second case, not.

find: (?i)\\(?:([^\\a-z])|[\\a-z])?
replace: $1 or \1

expanded

 (?i)                   # case insensitive  \\                     # '\' removed  (?:                    # cluster start       ( [^\\a-z] )           # (1), punctuation written    |                       # or,       [\\a-z]                # rest, removed  )?                     # cluster end, , optional eos 

Comments