Skip to content

Using RegEx with mete charecters

prem 0

Asked Sep 2, 2005, 3:10 AM EDT1 answer
Share
LinkedInX
Hello friends,
I have problems in using RegEx.replace method
with meta-characters.

For ex: Regex.Replace("**", "/t");

Sincae * is the part of RegEx syntex it throes some errors.
I tried with "//*" and it works. But I want use many meta-charecters.

Its a console application. I want the users to input search string and reolace string.

Ex:
repit ** /t
(Replaceing two astrics with tab)

Escaping meta chars is not helping here....

Any tips?

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    Have you looked into using the Regex.Escape() method?

    If you are storing the search and replace strings that the user types in then do something like this:

    string result = Regex.Replace(someTextVar, Regex.Escape(userLookFor), userReplaceWith);

    I would have to wonder though, are your users allowed to use wildcards or are all their "find" and "replaces" characters supposed to be literal character and not wildcards?
    0