|
-
Jun 12th, 2007, 11:02 AM
#1
Thread Starter
Hyperactive Member
the @ symbol in regular expressions
This might sound like a dumb question but I haven't seen this anywhere. I noticed that a lot of examples have the @ before the regex, why is that?
I haven't been using it and it is fine. My regex just look like this
RegEx tableOpenRegex = new RegEx("<table");
works fine - what am I missing...
Thanks
-
Jun 12th, 2007, 12:07 PM
#2
Re: the @ symbol in regular expressions
The '@' symbol prefixes a verbatim string literal. It is used to indicate that you do not wish escape sequences in the string to be parsed (all except for \"). This is useful in regular expressions because they use the same escape character as C# does ('\'). If the verbatim literal form is not used, you need to escape the escape characters, which results in an expression that is hard to read and difficult to port.
-
Jun 12th, 2007, 02:27 PM
#3
Re: the @ symbol in regular expressions
If you have the regular expression
You'd usually say
Code:
string regEx = "123\\.aspx(?!\\.)";
But it'd be easier to read if you said
Code:
string regEx = @"123\.aspx(?!\.)";
Also, it's useful when you want a very readable large string.
Code:
string vbfFooter = @" Jupitermedia Corporation has two divisions: Jupiterimages and Jupiter Online Media
Jupitermedia Corporate Info
Copyright 2007 Jupitermedia Corporation All Rights Reserved.
Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.
Web Hosting | Newsletters | Tech Jobs | Shopping | E-mail Offers";
-
Jun 13th, 2007, 07:52 AM
#4
Thread Starter
Hyperactive Member
[Resolved] the @ symbol in regular expressions
Ahh - thanks. I just read a article about it online not to long ago and they never even mentioned it - or I missed it... My regex's where pretty simple so it was never a problem.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|