**What is a Regular Expression?**

A regular expression (regex or regexp for short) is a special text string for describing a search pattern. Regular expression is written in a formal language that can be interpreted by a regular expression processor, a program that either serves as a parser generator or examines text and identifies parts that match the provided specification.

###### REGULAR EXPRESSIONS – FORMAT

Regular expressions in JavaScript take

the form:

var RegEx = /pattern/modifiers;

###### REGULAR EXPRESSIONS – MODIFIERS

**/g ** Global matching

**/i ** Case insensitive

**/s ** Single line mode

**/m** Multi line mode

###### REGULAR EXPRESSIONS – PATTERNS

^ |
Start of string |

$ |
End of string |

. |
Any single character |

(a|b) |
a or b |

(…) |
Group section |

[abc] |
Item in range (a or b or c) |

[^abc] |
Not in range (not a or b or c) |

a? |
Zero or one of a |

a* |
Zero or more of a |

a+ |
One or more of a |

a{3} |
Exactly 3 of a |

a{3,} |
3 or more of a |

a{3,6} |
Between 3 and 6 of a |

!(pattern) |
“Not” prefix. Apply rule when URL does not match pattern. |

Advertisements