How to substitute/replace escape characters

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

How to substitute/replace escape characters

John Preimonas-2
Hi,
I was (not) being clever and replaced “’” (apos) characters with + characters in a csv file which I then uploaded into my eXist database, e.g. d’Honour was changed to d+Honour. I also did it for brackets, e.g. (Foo) was changed to +Foo+.

Now that I have the data in the database I would like to change these characters back. How do I do it, seeing as a literal + cannot be matched. I usually want to do the following:

let $persons := collection(‘/db/apps/foo’)/persons[matches(idNotes, “+”)]
let $text-before := substring-before($persons/idNotes, “+”)
let $text-after := substring-after($persons/idNotes, “+”)
let $changer := “’”
let $new-text := $text-before || $changer || $text-after
let $result :=  update replace $persons/idNotes with <idNotes> { $new-text } </idNotes>
return $new-text

Cheers,
John
------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
Exist-open mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/exist-open
Reply | Threaded
Open this post in threaded view
|

Re: How to substitute/replace escape characters

Jens Østergaard Petersen-2
Hi John,

let $persons := collection('/db/apps/foo')/persons[matches(idNotes, '\+’)]

matches (if there is anything to match).

Which error do you get?

Jens

On 4 Jul 2015 at 09:51:26, John Preimonas ([hidden email]) wrote:

Hi,
I was (not) being clever and replaced “’” (apos) characters with + characters in a csv file which I then uploaded into my eXist database, e.g. d’Honour was changed to d+Honour. I also did it for brackets, e.g. (Foo) was changed to +Foo+.

Now that I have the data in the database I would like to change these characters back. How do I do it, seeing as a literal + cannot be matched. I usually want to do the following:

let $persons := collection(‘/db/apps/foo’)/persons[matches(idNotes, “+”)]
let $text-before := substring-before($persons/idNotes, “+”)
let $text-after := substring-after($persons/idNotes, “+”)
let $changer := “’”
let $new-text := $text-before || $changer || $text-after
let $result := update replace $persons/idNotes with <idNotes> { $new-text } </idNotes>
return $new-text

Cheers,
John
------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
Exist-open mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/exist-open

------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
Exist-open mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/exist-open