Tag: for dummies

@-quoted string literals

The advantage of @-quoting is that escape sequences are not processed, which makes it easy to write, for example, a fully qualified file name:

@”c:\Docs\Source\a.txt” rather than “c:\\Docs\\Source\\a.txt”

To include a double quotation mark in an @-quoted string, double it:

@”””Ahoy!”” cried the captain.” -> “Ahoy!” cried the captain.

Regular expressions in C#

How to: Verify That Strings are in Valid E-Mail Format

bool IsValidEmail(string strIn){
// Return true if strIn is in valid e-mail format.
return Regex.IsMatch(strIn, @”^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$”);
}

Operators in brief

Operator Description
* Postfix unary operator signifying zero or more occurrences of the operand.
+ Postfix unary operator signifying one or more occurrences of the operand.
? Postfix unary operator signifying zero or one occurrence of the operand.
| Binary infix operator meaning “or”.
() Used to group items.

Escaping Characters

Ordinary characters, other than the ones in the table below, match themselves. That is, an “a” in a regular expression specifies that input should match an “a”.

Another significant difference in writing handwriting regular expressions is that you can only escape a limited set of characters within a regular expression. The following table outlines the allowed set of characters that can be escaped. Any other attempt to escape a character will result in an error being thrown by the recognizer.

Character
\*
\+
\?
\(
\)
\|
\\
\!
\.
\[
\]
\^
\{
\}
\$
\#