Escaping text string for use in Reg Ex???

Author: Matt Slay

Posted: 2011-03-25 at 09:43:06

I'm working on a re-write of the VFP app GoFish (search and replace tool).

One thing I am doing with the new version is that internally I'm using

Regular Expressions to perform the search rather than the original way it

worked which was that it just used the $ function to look for a string

match.

So the user will enter a search string which could very likely contain some

characters that are reserved characters in regular expressions. (i.e.

^[]\{}.,;+-$ etc.) I need to escape those characters in the user input so

the reg ex search will work properly.

There are lots of way one could iterate over the input string to escape all

the special characters, and I'm sure there are some trick one must figure

out to do it correctly, so, before I re-invent the wheel here, I'm asking

around to see if anyone already has the code to do this.

Anyone?

--- StripMime Report -- processed MIME parts ---

multipart/alternative

text/plain (text body -- kept)

text/html

---

_______________________________________________

Post Messages to: ProFox@leafe.com

Subscription Maintenance: http://leafe.com/mailman/listinfo/profox

OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech

Searchable Archive: http://leafe.com/archives/search/profox

This message: http://leafe.com/archives/byMID/profox/031d01cbeaf2$93825ad0$ba871070$@com

** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.

©2011 Matt Slay