HTML Tags
Character Charts
W3C Compliancy
CSS
PHP
Useful Tools
Regular Expressions
1. PATTERNS
 
 ExplanationE.g.Matches
 
^First char of expr.^aexpr beginning with a
 
$Final char of expr.x$expr ending with x
 
.Match any char.a.bexpr with an a, then any char, then b
 
*Match 0 or more occurrences of the preceding char.34*a '3', followed by 0 or more 4's
 
+Match 1 or more occurrences of the preceding char.34+a '3', followed by 1 or more 4's
 
?Match 0 or 1 occurrences of the preceding char.aeiouy?'aeiou' or 'aeiouy'
 
\Escape special chars.\?An actual '?'.
 
[]Any of a set of chars.[abc]expr containing 'a' or 'b' or 'c'
 
[-]Specify a range.[a-z]expr containing any lowercase letter
 
[^]Anything not in set of chars.^[^a-z]*$expr not containing any lowercase letters
 
\dA digit – equivalent of [0-9]\d\dtwo consecutive digits
 
\wA single alphanumeric char – or underscore.#\w#'#', then an alphanumeric char, then another '#'
 
\sA single whitespace char – space, tab, form feed, line feed.^\sexpression beginning with white space
 
\rCarriage return.^\rexpr beginning with carriage return
 
\nLine feed.\r\nexpr containing carriage return then line feed
 
()Match and remember match – see next section.(a)expr containing the letter 'a'
 
a|bMatch a or b. Can be used with ().(hi|hello)expr containing the word 'hi' or the word 'hello'
 
{n}Match n occurrences of pattern.^\d{5}$expr consisting of exactly 5 digits
 
{n,}Match n or more occurrences of pattern.^\d{5,}$expr consisting of 5 or more digits
 
{n,m}Match at least n and at most m occurrences of pattern.^\d{5,8}$expr consisting of 5-8 digits
 
2. USAGE
OperationsNow that you know how to match patterns, what can you do with this knowledge?
 
searchYou can search a string to see whether or not it contains a given pattern. Typically, if the pattern exists, the return value will be the position of its first occurrence.
 
replaceYou can search a string to see whether or not it contains a given pattern – and if it exists, you can replace it with a new value – search and replace.
 
splitYou can use a pattern as a delimiter for splitting a string into an array.
 
ParametersYou can indicate the type of pattern matching to use:
 
ignorecaseYou can indicate (with 'i') that case is to be ignored in a pattern match.
 
globalYou can indicate (with 'g') that every occurrence – not just the first – should be sought. In general, applicable to replace, as opposed to search.
 
Regular ExpressionThis is an object that can be declared. Its properties are the pattern to be searched for, as well as whether searches are global or case-sensitive. When is such an object useful?
 
languageIn some languages, pattern-matching operations are methods of the regular expression (regexp) object, so you simply have to declare one in order to carry out pattern-matching operations.
 
non-static valuesSometimes, you cannot use a string literal (like "abc") as the pattern to search for, since you do not know in advance what pattern you will need to search for. Here, regexps are invaluable, as they allow you to designate a variable as the pattern to search for.
 
EmphasisThere are three ways to invoke the pattern matching operations:
 
stringIn this case, the various operations are called as methods of the string object, and the pattern to search for (which can be a regular expression object) is a parameter of the method. This is common in Javascript.
 
regexpIn this case, a 'Regular Expression' object is declared. The various operations are called as methods of the regExp object, and the string to search in is a parameter of the method. This is common in VBscript.
 
functionIn this case, the pattern and the string to search for it are both arguments of a function. This is common in PHP.
 
Referring backWhen doing a search and replace operation, you may wish to refer back to part of the pattern matched when replacing. For example, you may wish to replace a phone number in the format '410-633-7788' with the area code. In such cases, you need to use two elements:
 
()As mentioned in the "PATTERNS" section, surround the portion of the match that you wish to 'remember' with parentheses. So in our example, you would search for the pattern ^(\d{3}).*$. This will match the entire phone number, but will 'remember' the first three digits.
 
$nNext, when you indicate the pattern with which to replace the match, you would use $1, indicating that you wish to replace the pattern matched with the first remembered pattern – in our case, the area code. $2, $3, etc. can be used too.
 
 
References:
 
??
 
 
 
 
Check this page for W3C Compliancy
 
Top of Page