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
There are currently no sponsors. Become a sponsor today!
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

$re = '/^\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)?(.*)/m'; $str = 'busybox ls -lain 1769542 -rw------- 1 10163 10163 0 Dec 13 21:06 0.txt 1769543 -rw------- 1 10163 10163 0 Nov 13 21:06 1.txt 1769561 -rw------- 1 10163 10163 0 Feb 13 2016 10.txt 1769562 -rw------- 1 10163 10163 0 Jan 13 2016 11.txt 1769544 -rw------- 1 10163 10163 0 Oct 13 21:06 2.txt 1769545 -rw------- 1 10163 10163 0 Sep 13 21:06 3.txt 1769546 -rw------- 1 10163 10163 0 Aug 13 21:06 4.txt 1769547 -rw------- 1 10163 10163 0 Jul 13 21:06 5.txt 1769550 -rw------- 1 10163 10163 0 Jun 13 2016 6.txt 1769552 -rw------- 1 10163 10163 0 May 13 2016 7.txt 1769559 -rw------- 1 10163 10163 0 Apr 13 2016 8.txt 1769560 -rw------- 1 10163 10163 0 Mar 13 2016 9.txt toolbox ls -l drwxr-xr-x root root 1970-03-01 01:33 acct drwxrwx--- system cache 2016-12-13 10:53 cache lrwxrwxrwx root root 1969-12-31 16:00 charger -> /sbin/healthd dr-x------ root root 1970-03-01 01:33 config lrwxrwxrwx root root 1970-03-01 01:33 d -> /sys/kernel/debug drwxrwx--x system system 2016-07-06 21:19 data -rw-r--r-- root root 614 1969-12-31 16:00 default.prop drwxr-xr-x root root 2016-12-10 00:23 dev lrwxrwxrwx root root 1970-03-01 01:33 etc -> /system/etc -rw-r--r-- root root 24061 1969-12-31 16:00 file_contexts dr-xr-x--- system system 1969-12-31 16:00 firmware -rw-r----- root root 4158 1969-12-31 16:00 fstab.angler -rwxr-x--- root root 1142576 1969-12-31 16:00 init -rwxr-x--- root root 98 1969-12-31 16:00 init.angler.diag.rc -rwxr-x--- root root 14044 1969-12-31 16:00 init.angler.rc -rwxr-x--- root root 524 1969-12-31 16:00 init.angler.sensorhub.rc -rwxr-x--- root root 9729 1969-12-31 16:00 init.angler.usb.rc -rwxr-x--- root root 941 1969-12-31 16:00 init.environ.rc toybox ls -la drwxr-xr-x 20 root root 0 1970-03-01 01:33 . drwxr-xr-x 20 root root 0 1970-03-01 01:33 .. drwxr-xr-x 235 root root 0 1970-03-01 01:33 acct drwxrwx--- 5 system cache 4096 2016-12-13 21:57 cache busybox ls -la /dev crw-rw---- 1 system camera 81, 4 1970-01-30 15:02 v4l-subdev3 crw-rw---- 1 system camera 81, 5 1970-01-30 15:02 v4l-subdev4 crw-rw---- 1 system camera 81, 6 1970-01-30 15:02 v4l-subdev5 crw-rw---- 1 system camera 81, 7 1970-01-30 15:02 v4l-subdev6 '; preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0); // Print the entire match result var_dump($matches);

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 PHP, please visit: http://php.net/manual/en/ref.pcre.php