Regular Expression

From DevSummit
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

THere are three dialects of regular expressions: BRE- basic regular expression ERE -Extended regular expression PCRE - Perl - compatible regular expression

You can do things like search for things that are formatted like and address or phone number.

It's not so great for HTML - it can't find things that are nested too far down. This is an acknowledged way down. If you need to do web-pages think about using something like Beautiful Soup.

grep is a common tool for finding basic regular expressions. egrep is for extended regular expressions.

BRE's a parenthesis is just a parenthis.

egreps allows you to look for things like 'r......t$' and you will be able to find everything that is eight letters long that starts with r and ends with t.

. is a wildcard ^ is the beginning of the line only [ ] brackets is for character class (any character in the list).

If you want to find any word that has the same character class of slugfest.

boxes = [aceimnorsuvwyx]

Searching for words in a british word a question mark means that the character in front of it is optional. 'colu?r'

'organis?z?e' does'nt work

'organi[sz]e' will pull both spellings

{ } allows a number

o{2} means words where oo occurs

what is a word that has three reference - that has back reference. {2,4} means that it occurs between 2 and 4 times.

[- ]? means it will find a hyphen or a space

[0-9] is the same as [0123456789]

[0-9]{16} will find 16 chsracters in a row.

egrep -q 'Aspiration'

Symbol times ? 0.1 {4} 4 + 1 or more

  • 0 or more