RSS

Regular Expressions Metacharacters:

06 Feb

A regular expression (regex or regexp for short) is a special text string for describing a search pattern, there are types for regular expressions or called Mmetacharacters or metasequences as listed below:

1. WildCard regexp:

The dot (.)
The dot (.) is used to match any one character… in order words.

Example: .ate
- will match late, date, sate or any four character expressions.
- Also match 8ate. (the character doesn’t have to be a letter).
- It won’t match ate because one character must substitute for the dot (.).

Example: Homepage.com
- Will match homepagescom, homepage4com, Homepagedcom.
- If you really want to match Homepage.com you will need to use a backslash like this: Homepage\.com

Asterisk or Star (*)
A star (*) match zero or more of the previous item… repeat the previous item zero or more times.

Example: Format PN0000
- How many people are searching for part number 34.
The part number PN000034
So you might use the keyword filter of regex … PN0*34 that will display all the searches for PN034 and PN0034 and PN00000000034

• Plus (+)
Plus (+) match one or more of the previous items… The simplest meaning of “previous items” is “previous character”.

Example: Rob+in
- Would return Robin, Robbin, Robbbbin
- Alternatively, You can build a list of previous items by using square brackets like this: [abc] this will return a, ab, cab, c , b , bbb…..etc

• Question mark (?)
The question mark (?) is matches zero or one of the previous expression.

Example: abc?
- Matches ab or abc

Example: Labou?r
- It will match labour ( which does have a “u” which is the previous expression.
- And labor (which has zero of the previous expression. No “u” is included.

The pipe (|)
The pipe symbol (|) symbolizes the logical expression OR.

Example: Strings (‘FEA’ or ‘Finit’ or ‘FEM’)
- You can type FEA|Finit|FEM

Advertisement
 
Leave a comment

Posted by on February 6, 2010 in regular expressions

 

Tags: , , , , ,

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 )

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