How to build this pattern?

  • Thread starter Thread starter SL
  • Start date Start date
S

SL

A string cannot include any of these symbols: ^ ~ \ & -- % | “ [ ] : ;
= * ? > < #

if (Regex.IsMatch(someString, pattern))
MessageBox.Show("A string cannot include any of these symbols: ^ ~
\ & -- % | “ [ ] : ; = * ? > < #")

How to build this pattern?
Please help!
Thank you.
 
> A string cannot include any of these symbols: ^ ~ \ & -- % | =3F [ ] : ;
= * ? > < #

if (Regex.IsMatch(someString, pattern))
MessageBox.Show("A string cannot include any of these symbols: ^ ~
\ & -- % | =3F [ ] : ; = * ? > < #")

How to build this pattern?

Do you have to do it with regular expressions? I mean, it's feasibly -
but using string.IndexOfAny is simpler.
 
A string cannot include any of these symbols: ^ ~ \ & -- % | =3F [ ] : ;
= * ? > < #
if (Regex.IsMatch(someString, pattern))
* * MessageBox.Show("A string cannot include any of these symbols: ^ ~
\ & -- % | =3F [ ] : ; = * ? > < #")
How to build this pattern?

Do you have to do it with regular expressions? I mean, it's feasibly -
but using string.IndexOfAny is simpler.

--
Jon Skeet -
Web site:http://www.pobox.com/~skeet*
Blog:http://www.msmvps.com/jon.skeet
C# in Depth:http://csharpindepth.com

Indeed :)
 
string t = @"^ ~ \ & -- % | “ [ ] : ;> = * ? > < #";
Pattern = "^[" + t + "]+?";

Regex.IsMatch(someString, t)
 
A string cannot include any of these symbols: ^ ~ \ & -- % | “ [ ] : ;
= * ? > < #
if (Regex.IsMatch(someString, pattern))
   MessageBox.Show("A string cannot include any of these symbols: ^~
\ & -- % | “ [ ] : ; = * ? > < #")

try pattern "\\^|~|\\|&|--|%|\\||\"|\\[|\\]|:|;|=|>|<|#"

then
if (! Regex.IsMatch(someString, pattern))
MessageBox.Show("A string cannot include any of these
symbols: ^ ~ \ & -- % | “ [ ] : ; = * ? > < #")

Regards,
-Ratnesh
S7 Software
 
A string cannot include any of these symbols: ^ ~ \ & -- % | “ [ ] : ;
= * ? > < #
if (Regex.IsMatch(someString, pattern))
   MessageBox.Show("A string cannot include any of these symbols:^ ~
\ & -- % | “ [ ] : ; = * ? > < #")

try pattern  "\\^|~|\\\\|&|--|%|\\||\"|\\[|\\]|:|;|=|>|<|#"

then
if (! Regex.IsMatch(someString, pattern))
            MessageBox.Show("A string cannot include any of these
symbols: ^ ~ \ & -- % | “ [ ] : ; = * ? > < #")

Regards,
-Ratnesh
S7 Software

small correction
"\\^|~|\\|&|--|%|\\||\"|\\[|\\]|:|;|=|>|<|#"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top