Regular Expressions 101

Save & Manage Regex

  • Current Version: 1
  • Save & Share
  • Community Library

Flavor

  • PCRE2 (PHP)
  • ECMAScript (JavaScript)
  • Python
  • Golang
  • Java
  • .NET 7.0 (C#)
  • Rust
  • PCRE (Legacy)
  • Regex Flavor Guide

Function

  • Match
  • Substitution
  • List
  • Unit Tests
Sponsors
An explanation of your regex will be automatically generated as you type.
Detailed match information will be displayed here automatically.
  • All Tokens
  • Common Tokens
  • General Tokens
  • Anchors
  • Meta Sequences
  • Quantifiers
  • Group Constructs
  • Character Classes
  • Flags/Modifiers
  • Substitution
  • A single character of: a, b or c
    [abc]
  • A character except: a, b or c
    [^abc]
  • A character in the range: a-z
    [a-z]
  • A character not in the range: a-z
    [^a-z]
  • A character in the range: a-z or A-Z
    [a-zA-Z]
  • Any single character
    .
  • Alternate - match either a or b
    a|b
  • Any whitespace character
    \s
  • Any non-whitespace character
    \S
  • Any digit
    \d
  • Any non-digit
    \D
  • Any word character
    \w
  • Any non-word character
    \W
  • Non-capturing group
    (?:...)
  • Capturing group
    (...)
  • Zero or one of a
    a?
  • Zero or more of a
    a*
  • One or more of a
    a+
  • Exactly 3 of a
    a{3}
  • 3 or more of a
    a{3,}
  • Between 3 and 6 of a
    a{3,6}
  • Start of string
    ^
  • End of string
    $
  • A word boundary
    \b
  • Non-word boundary
    \B

Regular Expression
Processing...

Test String

Code Generator

Generated Code

import re regex = re.compile(r"^\s*(\d+)?\s?([rwxSTstdcb\-lp?]{10})\s+(\d+)?\s?(\S+)\s+(\S+)\s+([0-9,]+)?\s+(\d+)?\s?([0-9\-]{10}\s+[0-9:]{5}|[A-Z][a-z]{2}\s+[0-9]{1,2}\s+[0-9:]{4,5})\s((?:(?!\s\->\s).)*)(\s\->\s)?(.*)", flags=re.MULTILINE) test_str = ("busybox ls -lain\n" " 1769542 -rw------- 1 10163 10163 0 Dec 13 21:06 0.txt\n" " 1769543 -rw------- 1 10163 10163 0 Nov 13 21:06 1.txt\n" "1769561 -rw------- 1 10163 10163 0 Feb 13 2016 10.txt\n" "1769562 -rw------- 1 10163 10163 0 Jan 13 2016 11.txt\n" "1769544 -rw------- 1 10163 10163 0 Oct 13 21:06 2.txt\n" "1769545 -rw------- 1 10163 10163 0 Sep 13 21:06 3.txt\n" "1769546 -rw------- 1 10163 10163 0 Aug 13 21:06 4.txt\n" "1769547 -rw------- 1 10163 10163 0 Jul 13 21:06 5.txt\n" "1769550 -rw------- 1 10163 10163 0 Jun 13 2016 6.txt\n" "1769552 -rw------- 1 10163 10163 0 May 13 2016 7.txt\n" "1769559 -rw------- 1 10163 10163 0 Apr 13 2016 8.txt\n" "1769560 -rw------- 1 10163 10163 0 Mar 13 2016 9.txt\n\n" "toolbox ls -l\n" "drwxr-xr-x root root 1970-03-01 01:33 acct\n" "drwxrwx--- system cache 2016-12-13 10:53 cache\n" "lrwxrwxrwx root root 1969-12-31 16:00 charger -> /sbin/healthd\n" "dr-x------ root root 1970-03-01 01:33 config\n" "lrwxrwxrwx root root 1970-03-01 01:33 d -> /sys/kernel/debug\n" "drwxrwx--x system system 2016-07-06 21:19 data\n" "-rw-r--r-- root root 614 1969-12-31 16:00 default.prop\n" "drwxr-xr-x root root 2016-12-10 00:23 dev\n" "lrwxrwxrwx root root 1970-03-01 01:33 etc -> /system/etc\n" "-rw-r--r-- root root 24061 1969-12-31 16:00 file_contexts\n" "dr-xr-x--- system system 1969-12-31 16:00 firmware\n" "-rw-r----- root root 4158 1969-12-31 16:00 fstab.angler\n" "-rwxr-x--- root root 1142576 1969-12-31 16:00 init\n" "-rwxr-x--- root root 98 1969-12-31 16:00 init.angler.diag.rc\n" "-rwxr-x--- root root 14044 1969-12-31 16:00 init.angler.rc\n" "-rwxr-x--- root root 524 1969-12-31 16:00 init.angler.sensorhub.rc\n" "-rwxr-x--- root root 9729 1969-12-31 16:00 init.angler.usb.rc\n" "-rwxr-x--- root root 941 1969-12-31 16:00 init.environ.rc\n\n" "toybox ls -la\n" "drwxr-xr-x 20 root root 0 1970-03-01 01:33 .\n" "drwxr-xr-x 20 root root 0 1970-03-01 01:33 ..\n" "drwxr-xr-x 235 root root 0 1970-03-01 01:33 acct\n" "drwxrwx--- 5 system cache 4096 2016-12-13 21:57 cache\n\n" "busybox ls -la /dev\n" "crw-rw---- 1 system camera 81, 4 1970-01-30 15:02 v4l-subdev3\n" "crw-rw---- 1 system camera 81, 5 1970-01-30 15:02 v4l-subdev4\n" "crw-rw---- 1 system camera 81, 6 1970-01-30 15:02 v4l-subdev5\n" "crw-rw---- 1 system camera 81, 7 1970-01-30 15:02 v4l-subdev6\n\n\n") matches = regex.finditer(test_str) for match_num, match in enumerate(matches, start=1): print(f"Match {match_num} was found at {match.start()}-{match.end()}: {match.group()}") for group_num, group in enumerate(match.groups(), start=1): print(f"Group {group_num} found at {match.start(group_num)}-{match.end(group_num)}: {group}")

Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Python, please visit: https://docs.python.org/3/library/re.html