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

$re = '/(?:changed: \[)([A-Za-z0-9-.]+)(?:\]) => (\{([^{}]|(?R))*\})/s'; $str = 'ansible-playbook 2.4.6.0 config file = /etc/ansible/ansible.cfg configured module search path = [u\'/var/lib/awx/.ansible/plugins/modules\', u\'/usr/share/ansible/plugins/modules\'] ansible python module location = /opt/my-envs/ansible2.4_py2-7/lib/python2.7/site-packages/ansible executable location = /opt/my-envs/ansible2.4_py2-7/bin/ansible-playbook python version = 2.7.5 (default, Jun 11 2019, 12:19:05) [GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] Using /etc/ansible/ansible.cfg as config file setting up inventory plugins Parsed /tmp/awx_29075__71hcp3b/tmpl6ec9o_0 inventory source with script plugin [DEPRECATION WARNING]: \'include\' for playbook includes. You should use \'import_playbook\' instead. This feature will be removed in version 2.8. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg. Loading callback plugin awx_display of type stdout, v2.0 from /var/lib/awx/venv/awx/lib/python3.6/site-packages/ansible_runner/callbacks/awx_display.py PLAYBOOK: playbook_deploy_main.yml ********************************************* 2 plays in playbook_deploy_main.yml PLAY [Installing configuration to JUNOS device] ******************************** META: ran handlers TASK [Install rendered configuration to acm-lab-core1.expedient.com] *********** task path: /var/lib/awx/projects/_23__deploy/playbook_deploy_juniper.yml:7 <acm-lab-core1.expedient.com> using connection plugin netconf <acm-lab-core1.expedient.com> socket_path: /var/lib/awx/.ansible/pc/d05e057c6f Using module file /opt/my-envs/ansible2.4_py2-7/lib/python2.7/site-packages/ansible/modules/network/junos/junos_config.py <acm-lab-core1.expedient.com> ESTABLISH LOCAL CONNECTION FOR USER: awx <acm-lab-core1.expedient.com> EXEC /bin/sh -c \'echo ~ && sleep 0\' <acm-lab-core1.expedient.com> EXEC /bin/sh -c \'( umask 77 && mkdir -p "` echo /var/lib/awx/.ansible/tmp/ansible-tmp-1580756130.95-273172941190466 `" && echo ansible-tmp-1580756130.95-273172941190466="` echo /var/lib/awx/.ansible/tmp/ansible-tmp-1580756130.95-273172941190466 `" ) && sleep 0\' <acm-lab-core1.expedient.com> PUT /tmp/tmpv0PKXI TO /var/lib/awx/.ansible/tmp/ansible-tmp-1580756130.95-273172941190466/junos_config.py <acm-lab-core1.expedient.com> EXEC /bin/sh -c \'chmod u+x /var/lib/awx/.ansible/tmp/ansible-tmp-1580756130.95-273172941190466/ /var/lib/awx/.ansible/tmp/ansible-tmp-1580756130.95-273172941190466/junos_config.py && sleep 0\' <acm-lab-core1.expedient.com> EXEC /bin/sh -c \'/usr/bin/python /var/lib/awx/.ansible/tmp/ansible-tmp-1580756130.95-273172941190466/junos_config.py; rm -rf "/var/lib/awx/.ansible/tmp/ansible-tmp-1580756130.95-273172941190466/" > /dev/null 2>&1 && sleep 0\' [WARNING]: argument username has been deprecated and will be removed in a future version [WARNING]: argument host has been deprecated and will be removed in a future version [WARNING]: argument timeout has been deprecated and will be removed in a future version [WARNING]: argument password has been deprecated and will be removed in a future version changed: [acm-lab-core1.expedient.com] => { "changed": true, "failed": false, "invocation": { "module_args": { "backup": false, "comment": "configured by junos_config", "confirm": 0, "confirm_commit": false, "host": "acm-lab-core1.expedient.com", "lines": null, "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", "port": null, "provider": null, "replace": null, "rollback": null, "src_format": "text", "ssh_keyfile": null, "timeout": 300, "transport": null, "update": "merge", "username": "svcansible", "zeroize": false } } }'; 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