Friday, October 14, 2011

notes: Regular Expressions

| - Represents 'OR' Statements
EX: '21|31' = Will match either 21 or 31 in a line.

[ ] - SQUARE BRACKET :Represents a range of characters
EX: [1-4] = Will match any in the range 1 to 4.
EX: [67] = Will match either 6 or 7.

. - DOT : Matches any single character
EX: [1-4].[67] = Match 1/2/3/4 then anything character, then 6/7, thus 156 or 397.

^ - CAROT : Matches beginning of string
EX: ^21 in '213 317 31 218 731' = Will only match the first 21.

$ - DOLLAR : Matches end of string
EX: $31 in '213 317 31 218 731' = Will only match the 31 at the end.

_ - UNDERSCORE : Matches any Delimiter (beginning, end, space, tab, comma)
EX: _31_ in '213 317 31 218 731' = Will only match the 31 in the middle.

( ) - PARENTHESIS : are used for "and" operations. To group things together.
EX: (213|218)_31 = Matches 213 or 218 followed by 31, ie '213 317' or '218 31'.

{An Atom is a single preceding character or preceding group }
{The special characters *,?,+ all apply repetition to what immediately precedes them}.

* - ASTERISK : Matches ZERO or MORE atoms(single or group of characters)
EX : _23(_78)*_45_ = Will match "23 45" or "23 78 45" OR "23 78 78 78 78 45".

? - QUESTION MARK : Matches ZERO or ONE atoms
EX : _23(_78)?_45_ = Will match "23 45" OR "23 78 45".

+ - PLUS : Matches ONE or more Atoms
EX : _23(_78)+_45_ = Will match "23 78 45" OR "23 78 78 78 78 78 78 45".

\ - BACKSLASH : Removes the special meaning of one of the above characters.
EX: ^\(213_ = will match (213 at the beginning of string.

REGEX Examples
*-----------------*
_100_ - Passes/passed through AS 100 
^100$ - Directly connected to AS 100 (begins and ends in AS 100
_100$ - Originated in AS 100
^100_ - Networks behind AS 100
^[0-9]+$ - AS Paths that is one AS long
^([0-9]+)(_\1)*$ - Networks originating in neighboring AS, with possible prependings
^$ - Networks originating in LOCAL AS
.* - Matches everything

No comments:

Post a Comment