Regular Expressions 101

Save & Share

  • Regex Version: ver. 2
  • Update Regex
    ctrl+⇧+s
  • Save new Regex
    ctrl+s
  • Add to Community Library

Flavor

  • PCRE2 (PHP >=7.3)
  • PCRE (PHP <7.3)
  • ECMAScript (JavaScript)
  • Python
  • Golang
  • Java 8
  • .NET 7.0 (C#)
  • Rust
  • Regex Flavor Guide

Function

  • Match
  • Substitution
  • List
  • Unit Tests

Tools

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

/
/
gmi

Test String

Code Generator

Generated Code

$re = '/(?!FROM|INTO|NEXTVAL|UPDATE|JOIN)\S*\s*|\w+\s[\s`\'"]*(\w[\w\.-_]*)/mi'; $str = 'select * from ( select distinct materialwa0_.id as col_0_0_ from PDMBOM2.materialways materialwa0_ where materialwa0_.name=? and materialwa0_.revision=? ) where rownum <= ? SELECT userlocal0_.id AS id104_, userlocal0_.PIN AS PIN104_, userlocal0_.PINQueryTime AS PINQuery3_104_, userlocal0_.fk_acceptChannel AS fk78_104_, userlocal0_.acceptOddsChanges AS acceptOd4_104_, userlocal0_.activationKey AS activati5_104_, userlocal0_.activationKeyExpirationDate AS activati6_104_, userlocal0_.active AS active104_, userlocal0_.approved AS approved104_, userlocal0_.automaticRating AS automati9_104_, userlocal0_.automaticRatingLive AS automat10_104_, userlocal0_.bannerId AS bannerId104_, userlocal0_.blocked AS blocked104_, userlocal0_.blockedAmount AS blocked13_104_, userlocal0_.blockedCash AS blocked14_104_, userlocal0_.closedAt AS closedAt104_, userlocal0_.confirmBonusId AS confirm16_104_, userlocal0_.fk_contact AS fk79_104_, userlocal0_.contactMethods AS contact17_104_, userlocal0_.created AS created104_, userlocal0_.currency AS currency104_, userlocal0_.deactivatedUntil AS deactiv20_104_, userlocal0_.deactivatedUntilCasino AS deactiv21_104_, userlocal0_.deactivatedUntilLiveCasino AS deactiv22_104_, userlocal0_.deactivationDate AS deactiv23_104_, userlocal0_.deactivationReason AS deactiv24_104_, userlocal0_.deleteBefore AS deleteB25_104_, userlocal0_.deletionDate AS deletio26_104_, userlocal0_.emailFormat AS emailFo27_104_, userlocal0_.externalIdentifier AS externa28_104_, userlocal0_.failedLogins AS failedL29_104_, userlocal0_.favouriteEvents AS favouri30_104_, userlocal0_.favouriteGroups AS favouri31_104_, userlocal0_.favouriteParticipants AS favouri32_104_, userlocal0_.favouriteResultTypes AS favouri33_104_, userlocal0_.firstPayinAmount AS firstPa34_104_, userlocal0_.firstPayinClientType AS firstPa35_104_, userlocal0_.firstPayinDate AS firstPa36_104_, userlocal0_.flags AS flags104_, userlocal0_.flags1 AS flags38_104_, userlocal0_.gamblingVolume AS gamblin39_104_, userlocal0_.hostConfirmationDate AS hostCon40_104_, userlocal0_.lastAutoRatingDate AS lastAut41_104_, userlocal0_.lastBetDate AS lastBet42_104_, userlocal0_.lastCCBlocking AS lastCCB43_104_, userlocal0_.lastCasinoChipTransfer AS lastCas44_104_, userlocal0_.lastInactiveFeeChargeAttemptDate AS lastIna45_104_, userlocal0_.lastLiveCasinoChipTransfer AS lastLiv46_104_, userlocal0_.lastLogin AS lastLogin104_, userlocal0_.lastPayinAmount AS lastPay48_104_, userlocal0_.lastPayinDate AS lastPay49_104_, userlocal0_.lastPayinType AS lastPay50_104_, userlocal0_.login AS login104_, userlocal0_.loginCounter AS loginCo52_104_, userlocal0_.lowerLogin AS lowerLogin104_, userlocal0_.manualRating AS manualR54_104_, userlocal0_.manualRatingLive AS manualR55_104_, userlocal0_.manualRatingLiveUpdated AS manualR56_104_, userlocal0_.manualRatingUpdated AS manualR57_104_, userlocal0_.masterId AS masterId104_, userlocal0_.mobileOffering AS mobileO59_104_, userlocal0_.notShowPopupFlag AS notShow60_104_, userlocal0_.passGbglobal AS passGbg61_104_, userlocal0_.password AS password104_, userlocal0_.passwordExpiryDate AS passwor63_104_, userlocal0_.passwordHashType AS passwor64_104_, userlocal0_.ratingFollowUpAt AS ratingF65_104_, userlocal0_.ratingFollowUpBy AS ratingF66_104_, userlocal0_.ratingLiveFollowUpAt AS ratingL67_104_, userlocal0_.ratingLiveFollowUpBy AS ratingL68_104_, userlocal0_.reactivationDate AS reactiv69_104_, userlocal0_.registrationClientType AS registr70_104_, userlocal0_.registrationIp AS registr71_104_, userlocal0_.sessionId AS sessionId104_, userlocal0_.shopPassword AS shopPas73_104_, userlocal0_.stars AS stars104_, userlocal0_.fk_ticketPaymentData AS fk80_104_, userlocal0_.unspentTurnaroundSum AS unspent75_104_, userlocal0_.useDynamicRoles AS useDyna76_104_, userlocal0_.uuid AS uuid104_ FROM user_User userlocal0_ WHERE userlocal0_.login=? SELECT * FROM order_refactor o LEFT JOIN order_data od ON o.id = od.order_id WHERE o.id = :id Expected: "order_refactor" but: was "order_data"'; 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