try see compare understand learn JavaScript Regular Expressions

Basics | |
---|---|

. (dot) | Any character except newline |

a | The character a |

ab | The string ab |

a|b | a or b |

a* | 0 or more a's |

\ | Escapes a special character |

Quantifiers | |

* | 0 or more |

+ | 1 or more |

? | 0 or 1 |

❴2❵ | Exactly 2 times |

❴2,8❵ | Between 2 and 8 times |

❴2,❵ | 2 or more times |

Character Classes | |

[a-z0-9] | Any of a to z and 0 to 9 |

[^0-9] | To exclude any of 0 to 9 |

\d | Digit 0 to 9 |

\D | Non digit |

\s | Whitespace |

\S | Non whitespace |

\w | A word |

\W | A non word |

Anchors | |

^ | Start of string |

$ | End of string |

\b | Word boundary |

\B | Non-word boundary |

Options | |

g | Global Match |

i | Ignore case |

m | ^ and $ match start and end of line |

Lookaround | |

(?:x) | Non-capturing grouping |

x(?=y) | Positive lookahead |

x(?!y) | Negative lookahead |

(?<=y)x | Positive lookbehind |

(?<!y)x | Negative lookbehind |