Regular Expressions 101

Save & Share

  • Current Version: 2
  • Update Regex
    ctrl+⇧+s
  • Save new Regex
    ctrl+s
  • Add to 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 = '/^[\w\d-]*(?=\=)/m'; $str = '# This file may be used to create an environment using: # $ conda create --name <env> --file <this file> # platform: osx-64 absl-py=0.7.1=py36_0 appnope=0.1.0=py36_1000 asn1crypto=0.24.0=py36_1003 astor=0.7.1=py_0 attrs=19.1.0=py_0 backcall=0.1.0=py_0 bleach=3.1.0=py_0 blinker=1.4=py_1 boto=2.49.0=py_0 boto3=1.9.210=py_0 botocore=1.12.210=py_0 bz2file=0.98=py_0 c-ares=1.15.0=h01d97ff_1001 ca-certificates=2019.6.16=hecc5488_0 certifi=2019.6.16=py36_1 cffi=1.12.3=py36hccf1714_0 chardet=3.0.4=py36_1003 cryptography=2.7=py36h212c5bf_0 cycler=0.10.0=py_1 cymem=2.0.2=py36h6de7cb9_0 cython-blis=0.2.4=py36h01d97ff_1 decorator=4.4.0=py_0 defusedxml=0.5.0=py_1 docutils=0.15.2=py36_0 en-core-web-lg=2.1.0=pypi_0 en-core-web-md=2.1.0=pypi_0 en-core-web-sm=2.1.0=pypi_0 entrypoints=0.3=py36_1000 freetype=2.10.0=h24853df_1 funcy=1.13=py_0 future=0.17.1=py36_1000 gast=0.2.2=py_0 gensim=3.4.0=py36h1de35cc_0 grpcio=1.22.0=py36h6ef0057_0 h5py=2.9.0=nompi_py36h6248fd5_1104 hdf5=1.10.5=nompi_h0cbb7df_1100 idna=2.8=py36_1000 ipykernel=5.1.2=py36h5ca1d4c_0 ipython=7.7.0=py36h5ca1d4c_0 ipython_genutils=0.2.0=py_1 jedi=0.15.1=py36_0 jinja2=2.10.1=py_0 jmespath=0.9.4=py_0 joblib=0.13.2=py_0 jpeg=9c=h1de35cc_1001 jsonschema=3.0.2=py36_0 jupyter_client=5.3.1=py_0 jupyter_core=4.4.0=py_0 keras-applications=1.0.7=py_1 keras-preprocessing=1.0.9=py_1 kiwisolver=1.1.0=py36h770b8ee_0 libblas=3.8.0=12_openblas libcblas=3.8.0=12_openblas libcxx=8.0.0=4 libcxxabi=8.0.0=4 libffi=3.2.1=h6de7cb9_1006 libgfortran=3.0.1=0 liblapack=3.8.0=12_openblas libopenblas=0.3.7=hd44dcd8_1 libpng=1.6.37=h2573ce8_0 libprotobuf=3.9.1=hfbae3c0_0 libsodium=1.0.17=h01d97ff_0 libtiff=4.0.10=hd08fb8f_1003 lz4-c=1.8.3=h6de7cb9_1001 markdown=3.1.1=py_0 markupsafe=1.1.1=py36h1de35cc_0 matplotlib-base=3.1.1=py36h3a684a6_1 mistune=0.8.4=py36h1de35cc_1000 murmurhash=1.0.0=py36h0a44026_0 nbconvert=5.6.0=py_0 nbformat=4.4.0=py_1 ncurses=6.1=h0a44026_1002 nltk=3.4.4=py_0 notebook=6.0.0=py36_0 numexpr=2.7.0=py36h86efe34_0 numpy=1.17.0=py36h6b0580a_0 oauthlib=3.0.1=py_0 olefile=0.46=py_0 openssl=1.1.1c=h01d97ff_0 pandas=0.25.0=py36h86efe34_0 pandoc=2.7.3=0 pandocfilters=1.4.2=py_1 parso=0.5.1=py_0 patsy=0.5.1=py_0 pexpect=4.7.0=py36_0 pickleshare=0.7.5=py36_1000 pip=19.2.2=py36_0 plac=0.9.6=py36_0 preshed=2.0.1=py36h6de7cb9_0 prometheus_client=0.7.1=py_0 prompt_toolkit=2.0.9=py_0 protobuf=3.9.1=py36h6de7cb9_0 ptyprocess=0.6.0=py_1001 pycountry=19.8.18=pypi_0 pycparser=2.19=py36_1 pygments=2.4.2=py_0 pyjwt=1.7.1=py_0 pyopenssl=19.0.0=py36_0 pyparsing=2.4.2=py_0 pyrsistent=0.15.4=py36h01d97ff_0 pysocks=1.7.0=py36_0 python=3.6.7=h94afb7f_1005 python-dateutil=2.8.0=py_0 pytz=2019.2=py_0 pyzmq=18.0.2=py36hee98d25_2 readline=8.0=hcfe32e1_0 requests=2.22.0=py36_1 requests-oauthlib=1.2.0=py_0 retrying=1.3.3=py_2 s3transfer=0.2.1=py36_0 scipy=1.3.1=py36hab3da7d_2 seaborn=0.9.0=py_1 send2trash=1.5.0=py_0 setuptools=41.0.1=py36_0 simplejson=3.16.1=py36h470a237_0 six=1.12.0=py36_1000 smart_open=1.8.4=py_0 snowballstemmer=1.9.0=py_0 sortedcollections=1.1.2=py_0 sortedcontainers=2.1.0=py_0 spacy=2.1.8=py36h770b8ee_0 sqlite=3.29.0=hb7d70f7_0 srsly=0.0.7=py36h6de7cb9_0 statsmodels=0.10.1=py36heacc8b8_0 sumy=0.8.1=pypi_0 tensorboard=1.13.1=py36_0 tensorflow=1.13.1=py36_1 tensorflow-estimator=1.13.0=py36h24bf2e0_0 termcolor=1.1.0=py_2 terminado=0.8.2=py36_0 testpath=0.4.2=py_1001 thinc=7.0.8=py36h770b8ee_0 tk=8.6.9=h2573ce8_1002 tornado=6.0.3=py36h01d97ff_0 tqdm=4.33.0=py_0 traitlets=4.3.2=py36_1000 tweepy=3.8.0=py_0 urllib3=1.25.3=py36_0 wasabi=0.2.2=py_0 wcwidth=0.1.7=py_1 webencodings=0.5.1=py_1 werkzeug=0.15.5=py_0 wheel=0.33.4=py36_0 xz=5.2.4=h1de35cc_1001 zeromq=4.3.2=h6de7cb9_2 zlib=1.2.11=h01d97ff_1005 zstd=1.4.0=ha9f0a20_0'; 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