Match Meta Characters between strings( Regular Expressions)
-
Hi! need some help guys i want to match strings as whole words through regular expressions which contain meta characters. i tried the Regex.Escape method which "Guffa" suggested me .. it works good and don't throw any exception but it do not match the whole word also. m i again missing some thing.. here is my code:
public bool sSearchWholeWord()
{
string sSearchWord="***SPAM***";string content="hi this is \*\*\*SPAM\*\*\* testing"; string pattern = @"\\b" + Regex.Escape(sSearchWord) + @"\\b"; Regex re =new Regex(pattern,RegexOptions.IgnorePatternWhitespace); try { if(re.IsMatch(content)) { return true; } else { return false; } } catch(Exception e) { Response.Write(e.ToString()); return false; } }
this returns false but according to me it should return true also if i remove these meta charaters it returns true.. i dont know what m i missing or is there any other way of matching these meta characters? abhinav
abhinav
-
Hi! need some help guys i want to match strings as whole words through regular expressions which contain meta characters. i tried the Regex.Escape method which "Guffa" suggested me .. it works good and don't throw any exception but it do not match the whole word also. m i again missing some thing.. here is my code:
public bool sSearchWholeWord()
{
string sSearchWord="***SPAM***";string content="hi this is \*\*\*SPAM\*\*\* testing"; string pattern = @"\\b" + Regex.Escape(sSearchWord) + @"\\b"; Regex re =new Regex(pattern,RegexOptions.IgnorePatternWhitespace); try { if(re.IsMatch(content)) { return true; } else { return false; } } catch(Exception e) { Response.Write(e.ToString()); return false; } }
this returns false but according to me it should return true also if i remove these meta charaters it returns true.. i dont know what m i missing or is there any other way of matching these meta characters? abhinav
abhinav
abhinish wrote:
string pattern = @"\b" + Regex.Escape(sSearchWord) + @"\b";
Remove the 'word boundry' qualifiers. If you really need to check for a word, wrap specify spaces around the match and do explicit capture.
**
xacc.ide-0.2.0.50 - now with partial MSBuild support!
**