Daniel
Daniel

Reputation: 31

XQuery - remove all characters (illegal) that are NOT {A-Z,a-z,_,0-9}

I need an XQuery that removes any characters that are NOT {A-Z,a-z,_,0-9} - without having to explicitly specify them in the query.

Currently I am using:

for $x in /xml/TEST
let $i := concat('M', replace($x/ID, '[\[\]\(\)°: ]', ''))
return element {$i} {$x/* except $x/ID}

But whenever a new illegal character creeps up I need to adjust that command... so: not perfect.

Any ideas?

Thank you!

Upvotes: 1

Views: 1766

Answers (1)

wst
wst

Reputation: 11771

In regex you can use a negated character class by adding a carat ^ before the characters to be negated that will do exactly what you want:

replace($x/ID, '[^A-Za-z_0-9]', ''))

Upvotes: 6

Related Questions