Regular Expressions 101

Save & Share

Flavor

  • PCRE2 (PHP >=7.3)
  • PCRE (PHP <7.3)
  • ECMAScript (JavaScript)
  • Python
  • Golang
  • Java 8

Function

  • Match
  • Substitution
  • List
  • Unit Tests
`
(?m)(.?aws/credentials$|.?chef/(.*).pem$|.?gem/credentials$|.?irssi/config$|.?purple/accounts.xml$|.?recon-ng/keys.db$|.?ssh/config$|.?xchat2?/servlist_?.conf$|.agilekeychain$|.asc$|.bek$|.cscfg$|.dayone$|.exports|.extra|.functions|.fve$|.gnucash$|.jks$|.keychain$|.kwallet$|.log$|.mdf$|.ovpn$|.p12$|.pcap$|.pem$|.pfx$|.pkcs12$|.psafe3$|.rdp$|.sdf$|.sqlite$|.tblk$|.tpm$|Favorites.plist|LocalSettings.php|^(.|_)?netrc$|^.*_dsa$|^.*_ecdsa$|^.*_ed25519$|^.*_rsa$|^.?(bash_|zsh_)?aliases$|^.?(bash_|zsh_)?profile$|^.?(bash_|zsh_|sh_|z)?history$|^.?(bash|zsh|csh)rc$|^.?dbeaver-data-sources.xml$|^.?dockercfg$|^.?env$|^.?git-credentials$|^.?gitconfig$|^.?gitrobrc$|^.?htpasswd$|^.?irb_history$|^.?muttrc$|^.?mysql_history$|^.?npmrc$|^.?pgpass$|^.?psql_history$|^.?s3cfg$|^.?trc$|^.?tugboat$|^kdbx?$|^key(pair)?$|^key(store|ring)$|^sftp-config(.json)?$|^sql(dump)?$|carrierwave.rb|config(.inc)?.php$|config/hub$|configuration.user.xpl|credential|credentials.xml|database.yml|doctl/config.yaml$|etc/passwd$|etc/shadow$|filezilla.xml|jenkins.plugins.publish_over_ssh.BapSshPublisherPlugin.xml|journal.txt|knife.rb|omniauth.rb|otr.private_key|password|proftpdpasswd|recentservers.xml|robomongo.json|secret_token.rb|settings.py|terraform.tfvars|ventrilo_srv.ini)
`
gm
(?m)
match the remainder of the pattern with the following effective flags: gm
m modifier: multi line. Causes ^ and $ to match the begin/end of each line (not only begin/end of string)
1st Capturing Group
(.?aws/credentials$|.?chef/(.*).pem$|.?gem/credentials$|.?irssi/config$|.?purple/accounts.xml$|.?recon-ng/keys.db$|.?ssh/config$|.?xchat2?/servlist_?.conf$|.agilekeychain$|.asc$|.bek$|.cscfg$|.dayone$|.exports|.extra|.functions|.fve$|.gnucash$|.jks$|.keychain$|.kwallet$|.log$|.mdf$|.ovpn$|.p12$|.pcap$|.pem$|.pfx$|.pkcs12$|.psafe3$|.rdp$|.sdf$|.sqlite$|.tblk$|.tpm$|Favorites.plist|LocalSettings.php|^(.|_)?netrc$|^.*_dsa$|^.*_ecdsa$|^.*_ed25519$|^.*_rsa$|^.?(bash_|zsh_)?aliases$|^.?(bash_|zsh_)?profile$|^.?(bash_|zsh_|sh_|z)?history$|^.?(bash|zsh|csh)rc$|^.?dbeaver-data-sources.xml$|^.?dockercfg$|^.?env$|^.?git-credentials$|^.?gitconfig$|^.?gitrobrc$|^.?htpasswd$|^.?irb_history$|^.?muttrc$|^.?mysql_history$|^.?npmrc$|^.?pgpass$|^.?psql_history$|^.?s3cfg$|^.?trc$|^.?tugboat$|^kdbx?$|^key(pair)?$|^key(store|ring)$|^sftp-config(.json)?$|^sql(dump)?$|carrierwave.rb|config(.inc)?.php$|config/hub$|configuration.user.xpl|credential|credentials.xml|database.yml|doctl/config.yaml$|etc/passwd$|etc/shadow$|filezilla.xml|jenkins.plugins.publish_over_ssh.BapSshPublisherPlugin.xml|journal.txt|knife.rb|omniauth.rb|otr.private_key|password|proftpdpasswd|recentservers.xml|robomongo.json|secret_token.rb|settings.py|terraform.tfvars|ventrilo_srv.ini)
1st Alternative
.?aws/credentials$
.
matches any character (except for line terminators)
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
aws/credentials
matches the characters aws/credentials literally (case sensitive)
$ asserts position at the end of a line
2nd Alternative
.?chef/(.*).pem$
.
matches any character (except for line terminators)
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
chef/
matches the characters chef/ literally (case sensitive)
2nd Capturing Group
(.*)
.
matches any character (except for line terminators)
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
. matches any character (except for line terminators)
pem
matches the characters pem literally (case sensitive)
$ asserts position at the end of a line
3rd Alternative
.?gem/credentials$
.
matches any character (except for line terminators)
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
gem/credentials
matches the characters gem/credentials literally (case sensitive)
$ asserts position at the end of a line
4th Alternative
.?irssi/config$
.
matches any character (except for line terminators)
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
irssi/config
matches the characters irssi/config literally (case sensitive)
$ asserts position at the end of a line
5th Alternative
.?purple/accounts.xml$
.
matches any character (except for line terminators)
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
purple/accounts
matches the characters purple/accounts literally (case sensitive)
. matches any character (except for line terminators)
xml
matches the characters xml literally (case sensitive)
$ asserts position at the end of a line
6th Alternative
.?recon-ng/keys.db$
.
matches any character (except for line terminators)
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
recon-ng/keys
matches the characters recon-ng/keys literally (case sensitive)
. matches any character (except for line terminators)
db
matches the characters db literally (case sensitive)
$ asserts position at the end of a line
7th Alternative
.?ssh/config$
.
matches any character (except for line terminators)
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
ssh/config
matches the characters ssh/config literally (case sensitive)
$ asserts position at the end of a line
8th Alternative
.?xchat2?/servlist_?.conf$
.
matches any character (except for line terminators)
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
xchat
matches the characters xchat literally (case sensitive)
2
matches the character 2 with index 5010 (3216 or 628) literally (case sensitive)
/servlist
matches the characters /servlist literally (case sensitive)
_
matches the character _ with index 9510 (5F16 or 1378) literally (case sensitive)
. matches any character (except for line terminators)
conf
matches the characters conf literally (case sensitive)
$ asserts position at the end of a line
9th Alternative
.agilekeychain$
. matches any character (except for line terminators)
agilekeychain
matches the characters agilekeychain literally (case sensitive)
$ asserts position at the end of a line
10th Alternative
.asc$
. matches any character (except for line terminators)
asc
matches the characters asc literally (case sensitive)
$ asserts position at the end of a line
11th Alternative
.bek$
12th Alternative
.cscfg$
13th Alternative
.dayone$
14th Alternative
.exports
15th Alternative
.extra
16th Alternative
.functions
17th Alternative
.fve$
18th Alternative
.gnucash$
19th Alternative
.jks$
20th Alternative
.keychain$
21st Alternative
.kwallet$
22nd Alternative
.log$
23rd Alternative
.mdf$
24th Alternative
.ovpn$
25th Alternative
.p12$
26th Alternative
.pcap$
27th Alternative
.pem$
28th Alternative
.pfx$
29th Alternative
.pkcs12$
30th Alternative
.psafe3$
31st Alternative
.rdp$
32nd Alternative
.sdf$
33rd Alternative
.sqlite$
34th Alternative
.tblk$
35th Alternative
.tpm$
36th Alternative
Favorites.plist
37th Alternative
LocalSettings.php
38th Alternative
^(.|_)?netrc$
39th Alternative
^.*_dsa$
40th Alternative
^.*_ecdsa$
41st Alternative
^.*_ed25519$
42nd Alternative
^.*_rsa$
43rd Alternative
^.?(bash_|zsh_)?aliases$
44th Alternative
^.?(bash_|zsh_)?profile$
45th Alternative
^.?(bash_|zsh_|sh_|z)?history$
46th Alternative
^.?(bash|zsh|csh)rc$
47th Alternative
^.?dbeaver-data-sources.xml$
48th Alternative
^.?dockercfg$
49th Alternative
^.?env$
50th Alternative
^.?git-credentials$
51st Alternative
^.?gitconfig$
52nd Alternative
^.?gitrobrc$
53rd Alternative
^.?htpasswd$
54th Alternative
^.?irb_history$
55th Alternative
^.?muttrc$
56th Alternative
^.?mysql_history$
57th Alternative
^.?npmrc$
58th Alternative
^.?pgpass$
59th Alternative
^.?psql_history$
60th Alternative
^.?s3cfg$
61st Alternative
^.?trc$
62nd Alternative
^.?tugboat$
63rd Alternative
^kdbx?$
64th Alternative
^key(pair)?$
65th Alternative
^key(store|ring)$
66th Alternative
^sftp-config(.json)?$
67th Alternative
^sql(dump)?$
68th Alternative
carrierwave.rb
69th Alternative
config(.inc)?.php$
70th Alternative
config/hub$
71st Alternative
configuration.user.xpl
72nd Alternative
credential
73rd Alternative
credentials.xml
74th Alternative
database.yml
75th Alternative
doctl/config.yaml$
76th Alternative
etc/passwd$
77th Alternative
etc/shadow$
78th Alternative
filezilla.xml
79th Alternative
jenkins.plugins.publish_over_ssh.BapSshPublisherPlugin.xml
80th Alternative
journal.txt
81st Alternative
knife.rb
82nd Alternative
omniauth.rb
83rd Alternative
otr.private_key
84th Alternative
password
85th Alternative
proftpdpasswd
86th Alternative
recentservers.xml
87th Alternative
robomongo.json
88th Alternative
secret_token.rb
89th Alternative
settings.py
90th Alternative
terraform.tfvars
91st Alternative
ventrilo_srv.ini
Global pattern flags
g modifier: global. All matches (don't return after first match)
m modifier: multi line. Causes ^ and $ to match the begin/end of each line (not only begin/end of string)
Your regular expression does not match the subject string.

Regular Expression
No Match

`
`
gm

Test String