Page 1 of 1

Case sensitive sandr?

Posted: Wed Apr 11, 2012 10:31 am
by greer
To cater for certain foreign character words, we use an XML file of search and replace terms to switch out on our website, (for example, "sister" in French is "sœur"):

soeur => sœur

However, "Nunn" in French is "Sœur", (with an uppercase S), but due to the case-insensitive sandr, is also getting replaced with "sœur", (lowercase s). Here is our code:

<$file = "oelist.xml">
<read $file>
<$data = $ret>
<rex row ">><term>\P=!</term>+\F</term>" $data>
<$term = $ret>
<rex ">><termid>\P=!</termid>+\F</termid>" $term>
<$needles = $ret>
<rex ">><termuc>\P=!</termuc>+\F</termuc>" $term>
<$replace = $ret>
<sandr $needles $replace $TEXT>
<$TEXT = $ret>
Here is the structure of our xml file:
<term><termid>boeuf</termid><termuc>bœuf</termuc></term>
<term><termid>coeur</termid><termuc>cœur</termuc></term>
<term><termid>soeur</termid><termuc>sœur</termuc></term>
<term><termid>Soeur</termid><termuc>Sœur</termuc></term>
etc...

Is there an efficient way to perform this function with case sensitivity, (so that "soeur" becomes "sœur" and "Soeur" becomes "Sœur")?

Thanks!

Case sensitive sandr?

Posted: Wed Apr 11, 2012 10:50 am
by Kai
Prepend `\R' to your search expressions; then they will respect case. E.g. after you get $needles:

<sandr ">>=.+" "\\R\2" $needles>
<$needles = $ret>

Case sensitive sandr?

Posted: Wed Apr 11, 2012 11:05 am
by John
The other thing you might consider is just looking at the portion of the word you want to replace, e.g.

<term><termid>oe</termid><termuc>œ</termuc></term>

which will replace all the above words, and won't touch the first letter of the word. That will also handle any other words with œ in them.

Case sensitive sandr?

Posted: Wed Apr 11, 2012 11:17 am
by greer
Thanks guys, the first suggestion hit the nail on the head.