Regular Expression

Regular Expression also calls Regexp. There are two classes regular expressions: Basic Regexp (BRE) and Extended Regexp (ERE). Regexp should be put in double quotation marks.

It can be categorized to:

Strings

. – Can be any character.

Sample: #cat /etc/fstab | grep "U..D"

It returns the lines contains U, D and whatever 2 characters between its.

[] – Any specified single character.

Sample: #cat /etc/fstab | grep "U[UAB]ID"

It returnes the lines contains U, I, D and U or A or B.

[^] – Any character except specified single character.

Sample: #cat /etc/fstab | grep "[^AB]ID"

It returnes the lines contains I and D but no A or B in left.

[[:digit:]] – All digital characters.

[[:lower:]] – All lower case characters.

[[:upper:]] – All upper case characters.

[[:alpha:]] – All alphabet characters.

[[:alnum:]] – All alphnumeric characters.

[[:space:]] – All space.

[[:print:]] – All visible characters and space.

[[:blank:]] – Space and tab.

[[:punct:]] – Punctuation and symbols.

Counting

 

Location

 

Grouping

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.