Menü schliessen
Created: April 13th 2021
Last updated: July 14th 2023
Categories: IT Support
Author: Tim Fürer

RegEx: Basic Introduction

Tags:  guide,  regex
Donation Section: Background
Monero Badge: QR-Code
Monero Badge: Logo Icon Donate with Monero Badge: Logo Text
82uymVXLkvVbB4c4JpTd1tYm1yj1cKPKR2wqmw3XF8YXKTmY7JrTriP4pVwp2EJYBnCFdXhLq4zfFA6ic7VAWCFX5wfQbCC

In this guide, I'll introduce you to RegEx.

RegEx stands for 'Regular Expression'. It is used to make search patterns.

What a RegEx filter is made of

This is an example of a very basic RegEx filter, it will select every occurrence of 'word' in the target string:

/word/g

It consists of two delimiters, in this case we use slashes ('/'), the content (the filter pattern) between them, which is what we filter by and the flags after the delimiters, which configure the filter.

RegEx Tokens

RegEx Tokens can be utilized in the filter pattern.

Following Tokens, but not limited by, are available (at least in JavaScript). Here's a collection with examples and explanations:

  • .          Any single character.
  • a|b|c          Either a, b or c.
  • [abc]          Any single character mentioned inside square brackets.
  • [a-z]          Any single character between a and z.
  • [^abc]          Any single character, except ones mentioned inside square brackets.
  • [^a-z]          Any single character, except between a and z.
  • a?          Zero or one of a.
  • a*          Zero or more of a.
  • a+        One or more of a.
  • a{2}       Two of a.
  • a{2,}        Two or more of a.
  • a{2,4}        Between 2 and 4 of a.
  • (abc)        Capture group.
  • (?=abc)        Positive lookahead.
  • (?!abc)        Negative lookahead.
  • (?<=abc)        Positive lookbehind.
  • (?<!abc)        Negative lookbehind.

RegEx Flags

Like mentioned before, flags can configure how your filter works. The following flags are available (at least in JavaScript):

  • g        Global - Don't return after first match.
  • m        Multi line - ^ and $ match start and end of a line.
  • i        Insensitive - Case insensitive filter.
  • y        Sticky - Anchor to start of filter pattern or at end of most recent match.
  • u        Unicode - Utilize full Unicode.
  • s        Singe line - Dot token specifically also counts newline as character.