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
/
^(?:[[:^print:][:cntrl:]\s]|GIF89.{0,20})*<\?(?:php)?\s*function\s*generaterandomstring.{0,390}?getenv\(["']remote_addr['"]\);\s*\$message[\s*="\-]+.{0,350}?\$subject\s*=\s*"becu\s*rezult\s*\|\s*\$ip.{0,5700}?exit\(header\(["']location[:\s\w\/]+becu\.org.{0,250}?location:\s*\w+\.php\?\&.{0,90}?\$msg,"\$headers[[:punct:]\s]+$
/
gis
^ asserts position at start of the string
Non-capturing group
(?:[[:^print:][:cntrl:]\s]|GIF89.{0,20})*
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
1st Alternative
[[:^print:][:cntrl:]\s]
Match a single character present in the list below
[[:^print:][:cntrl:]\s]
[:^print:] matches the negation of print
[:cntrl:] matches a control character [\x00-\x1F\x7F]
\s matches any whitespace character (equivalent to [\r\n\t\f\v ])
2nd Alternative
GIF89.{0,20}
GIF89
matches the characters GIF89 literally (case insensitive)
.
matches any character
{0,20} matches the previous token between 0 and 20 times, as many times as possible, giving back as needed (greedy)
< matches the character < with index 6010 (3C16 or 748) literally (case insensitive)
\? matches the character ? with index 6310 (3F16 or 778) literally (case insensitive)
Non-capturing group
(?:php)?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
php
matches the characters php literally (case insensitive)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v ])
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
function
matches the characters function literally (case insensitive)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v ])
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
generaterandomstring
matches the characters generaterandomstring literally (case insensitive)
.
matches any character
{0,390}? matches the previous token between 0 and 390 times, as few times as possible, expanding as needed (lazy)
getenv
matches the characters getenv literally (case insensitive)
\( matches the character ( with index 4010 (2816 or 508) literally (case insensitive)
Match a single character present in the list below
["']
"'
matches a single character in the list "' (case insensitive)
remote_addr
matches the characters remote_addr literally (case insensitive)
Match a single character present in the list below
['"]
'"
matches a single character in the list '" (case insensitive)
\) matches the character ) with index 4110 (2916 or 518) literally (case insensitive)
; matches the character ; with index 5910 (3B16 or 738) literally (case insensitive)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v ])
\$ matches the character $ with index 3610 (2416 or 448) literally (case insensitive)
message
matches the characters message literally (case insensitive)
Match a single character present in the list below
[\s*="\-]
.
matches any character
\$ matches the character $ with index 3610 (2416 or 448) literally (case insensitive)
subject
matches the characters subject literally (case insensitive)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v ])
= matches the character = with index 6110 (3D16 or 758) literally (case insensitive)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v ])
"becu
matches the characters "becu literally (case insensitive)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v ])
rezult
matches the characters rezult literally (case insensitive)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v ])
\| matches the character | with index 12410 (7C16 or 1748) literally (case insensitive)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v ])
\$ matches the character $ with index 3610 (2416 or 448) literally (case insensitive)
ip
matches the characters ip literally (case insensitive)
.
matches any character
exit
matches the characters exit literally (case insensitive)
\( matches the character ( with index 4010 (2816 or 508) literally (case insensitive)
header
matches the characters header literally (case insensitive)
\( matches the character ( with index 4010 (2816 or 508) literally (case insensitive)
Match a single character present in the list below
["']
location
matches the characters location literally (case insensitive)
Match a single character present in the list below
[:\s\w\/]
becu
matches the characters becu literally (case insensitive)
\. matches the character . with index 4610 (2E16 or 568) literally (case insensitive)
org
matches the characters org literally (case insensitive)
.
matches any character
location:
matches the characters location: literally (case insensitive)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v ])
\w
matches any word character (equivalent to [a-zA-Z0-9_])
\. matches the character . with index 4610 (2E16 or 568) literally (case insensitive)
php
matches the characters php literally (case insensitive)
\? matches the character ? with index 6310 (3F16 or 778) literally (case insensitive)
\& matches the character & with index 3810 (2616 or 468) literally (case insensitive)
.
matches any character
\$ matches the character $ with index 3610 (2416 or 448) literally (case insensitive)
msg,"
matches the characters msg," literally (case insensitive)
\$ matches the character $ with index 3610 (2416 or 448) literally (case insensitive)
headers
matches the characters headers literally (case insensitive)
Match a single character present in the list below
[[:punct:]\s]
$ asserts position at the end of the string, or before the line terminator right at the end of the string (if any)
Global pattern flags
g modifier: global. All matches (don't return after first match)
i modifier: insensitive. Case insensitive match (ignores case of [a-zA-Z])
s modifier: single line. Dot matches newline characters
Your regular expression does not match the subject string.Try launching the debugger to find out why.

Regular Expression
No Match

/
/
gis

Test String