views:

26

answers:

1

Basically my issue is that users would like to search for a french word that has accented characters but without typing in the accented characters and then have the actual accented word appeared highlighted if found... So for example they would type in "declare" but in the result sets it would look like "déclare" and if found "déclare" would be highlighted.

My first thought was to just simply replace the characters with a regex but then I remembered that I would need to re-insert the replaced characters after the search... I was thinking of then using some sort of character map that would track position and the character so that when the search was finshed I could put the result set back to the way it was. This seems a little brute force to me and I was wondering if anyone had a better alternative? I'm using Visual Studio 2005 with this app.

Any advice would be much appreciated!

Thanks

+1  A: 

A regular expression by default matches text. The "replacement" mode is not the normal mode. So, what you want is in fact the default. The precise syntax will depend on your Regex engine, e.g. in .Net you'd use Regex.IsMatch()

MSalters
I'm not sure that that will work in my case. The search term in my case may not have an accented character. So if I had a regex that looked like [ÁÂàáâÈÉÊèéê] then did an is match I would not have a match.
Actually, it does work. When your user types in "declare", you create the regex "d[eèéê]cl[aàáâ]r[eèéê]". This will then match at position 5 in "j'ai déclaré", so you highlight starting at that position.
MSalters
Ahh ok I see what you mean. How would that look with a more dynamic regex? My regex skills are limited so I'm not sure how that would look.
I've given it some more thought and I'm not sure how that would work at all. If you don't know where the accented characters are how could you set up a regex for that?
At this point I'd suggest just tyring my "j'ai déclaré" example. Try to put that into code. If it doesn't work, ask a new question here.
MSalters