Wednesday, March 11, 2015

Regular Expression

Special character
Explanation
 .
The “.” matches any single character. For example, “d.g”matches “dog”, “dig”, “dug”, and any word that contains those characters, like “daggonnit”.
(exp)
The “()” segregates characters from the surrounding characters, so that you can use other metacharacters on the subexpression. For example, “d(o|i)g” matches “dog” and “dig”, but “do|ig” matches “do” and “ig”. A subexpression can also be used with repeated quantifiers to differentiate the characters meant for repetition. For example, “12(34){3}5” matches “123434345”.
|
The “|” matches either expression it separates. For example,  “dog|cat” matches “dog” or “cat”.
?
The “?” indicates that there are 0 or 1 of the previous character. For example, “ra?ise” matches on “raise” or “rise”. Note that you must enter Ctrl+Vand then the question mark, or else the ASA CLI help function is performed instead.
    •  
The “*” indicates that there are 0, 1, or any number of the previous character. For example, “mo*se” matches on “mse”, “mose”, “moose”, and so on.Continues…
+
The “+” indicates that there is at least 1 of the previous character. For example, “mo+se” matches on “mose” and “moose”, but not “mse”
{x} or {x,}
The “{}”, with a number between the braces, indicates the previous expression is repeated at least “x” times. For example, “ab(fd){2,}e” matches “abfdfde”, “abfdfdfde”, and so on
[abc]
The “[]” matches any character in the brackets. For example, “[Rr]” matches on “R” or “r”.
[^abc]
The “[^]” matches a single character that is notcontained within the brackets. For example, “[^abc]” matches any character other than “a”, “b”, or “c”; or “[^A-Z]” matches any single character that is not an uppercase letter
[a-c]
The “[-]” matches any character in the range. For example, “[A-Z]” matches any uppercase letter. You can also mix characters and ranges: “[abcq-z]” matches “a”, “b”, “c”, and “q” through “z”. You could also write this as “[a-cq-z]”.
" abc"
The “""” preserves trailing or leading spaces in the string. For example, " secret" preserves the leading space when it looks for a match.
^
The “^” specifies the beginning of a line
\
The “\”, when used with a regular expression metacharacter, matches a literal character. For example, “\.” matches a period (“.”). This is used when you want to match on a character that is itself a metacharacter.
\r
The “\r” matches on a carriage return.
\n
The “\n” matches on a new line.
\t
The “\t” matches on a tab
\f
The “\f” matches on a form feed (new page)
\x
The “\x” matches on an ASCII character specified by the two hexadecimal digits (NN).
\NNN
The “\” matches on any ASCII character specified as octal (the three digits listed).

No comments:

Post a Comment