Regular Expressions 101

Save & Share

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

/
/
mg

Test String

Substitution

Processing...

Code Generator

Generated Code

$re = '/\w+$/m'; $str = 'Name hfgh 0 fghfgh Ethereum ETH Binance Coin BNB Cardano ADA Tether USDT Solana SOL XRP XRP Polkadot DOT Dogecoin DOGE USD Coin USDC Terra LUNA Uniswap UNI SHIBA INU SHIB Avalanche AVAX Chainlink LINK Wrapped Bitcoin WBTC Litecoin LTC Binance USD BUSD Bitcoin Cash BCH Algorand ALGO Polygon MATIC Stellar XLM VeChain VET Cosmos ATOM Internet Computer ICP Axie Infinity AXS FTX Token FTT Filecoin FIL Ethereum Classic ETC TRON TRX Fantom FTM Dai DAI THETA THETA Bitcoin BEP2 BTCB Elrond EGLD Tezos XTZ Hedera HBAR Monero XMR NEAR Protocol NEAR Crypto.com Coin CRO PancakeSwap CAKE EOS EOS The Graph GRT Aave AAVE Flow FLOW Klaytn KLAY IOTA MIOTA eCash XEC Quant QNT Kusama KSM Bitcoin SV BSV Harmony ONE UNUS SED LEO LEO Neo NEO Waves WAVES Stacks STX TerraUSD UST THORChain RUNE Maker MKR BitTorrent BTT Zcash ZEC Celo CELO Helium HNT Dash DASH Amp AMP OMG Network OMG Chiliz CHZ Compound COMP Arweave AR Huobi Token HT Decred DCR Holo HOT Theta Fuel TFUEL NEM XEM OKB OKB Curve DAO Token CRV Nexo NEXO Enjin Coin ENJ Revain REV Decentraland MANA ICON ICX SushiSwap SUSHI Qtum QTUM TrueUSD TUSD yearn.finance YFI XDC Network XDC KuCoin Token KCS Mina MINA Celsius CEL Zilliqa ZIL Bitcoin Gold BTG Ravencoin RVN Perpetual Protocol PERP Ren REN Synthetix SNX Horizen ZEN renBTC RENBTC Telcoin TEL Basic Attention Token BAT dYdX DYDX Serum SRM Bancor BNT Pax Dollar USDP Secret SCRT Audius AUDIO IOST IOST Siacoin SC Celer Network CELR Mdex MDX 0x ZRX Ontology ONT NuCypher NU Raydium RAY Ankr ANKR UMA UMA DigiByte DGB Nano NANO The Sandbox SAND 1inch Network 1INCH SKALE Network SKL SwissBorg CHSB Voyager Token VGX IoTeX IOTX WOO Network WOO Dent DENT Gnosis GNO Neutrino USD USDN WAX WAXP Loopring LRC Fetch.ai FET Nervos Network CKB Function X FX Golem GLM Ocean Protocol OCEAN Injective Protocol INJ Kava KAVA Reserve Rights RSR Livepeer LPT Bitcoin Standard Hashrate Token BTCST Lisk LSK WINkLink WIN Alpha Finance Lab ALPHA DigitalBits XDB Storj STORJ Numeraire NMR COTI COTI Polymath POLY Swipe SXP Reef REEF Fei Protocol FEI WazirX WRX Bitcoin Diamond BCD XYO XYO GateToken GT VeThor Token VTHO Unibright UBT BakeryToken BAKE MediBloc MED Verge XVG Venus XVS SingularityNET AGIX ASD ASD Conflux CFX OriginTrail TRAC HUSD HUSD Ontology Gas ONG PAX Gold PAXG iExec RLC RLC Ardor ARDR Hive HIVE aelf ELF Civic CVC Status SNT StormX STMX Velas VLX Band Protocol BAND Prometeus PROM Orchid OXT Energy Web Token EWT Verasity VRA NKN NKN Ergo ERG Origin Protocol OGN Cartesi CTSI Ark ARK Badger DAO BADGER Orbs ORBS Stratis STRAX Oasis Network ROSE Constellation DAG MyNeighborAlice ALICE Augur REP Casper CSPR Enzyme MLN Polkastarter POLS Steem STEEM Syscoin SYS MaidSafeCoin MAID FUNToken FUN Metal MTL HEX HEX Lido stETH STETH Wrapped BNB WBNB Bitcoin Cash ABC BCHA Huobi BTC HBTC Symbol XYM Creditcoin CTC The Transfer Token TTT SafeMoon SAFEMOON BitDAO BIT yOUcash YOUC ECOMI OMI NXM NXM Counos X CCXX Kadena KDA Moonriver MOVR Venus BNB vBNB Rally RLY LINK LN Liquity USD LUSD DeFiChain DFI Coin98 C98 WhiteCoin XWC Convex Finance CVX Alitas ALT INO COIN INO Gala GALA MobileCoin MOB Illuvium ILV Braintrust BTRST Anchor Protocol ANC Persistence XPRT LUKSO LYXe Yield Guild Games YGG Tribe TRIBE Keep Network KEEP Pundi X[new] PUNDIX Rari Governance Token RGT Trust Wallet Token TWT Bitpanda Ecosystem Token BEST Bonfida FIDA Pirate Chain ARRR Frax FRAX Rocket Pool RPL Orbit Chain ORC Electroneum ETN WEMIX WEMIX KOK KOK Akash Network AKT MOBOX MBOX Alchemix ALCX HedgeTrade HEDG Telos TLOS JOE JOE Kyber Network Crystal v2 KNC Dogelon Mars ELON TrueFi TRU Beta Finance BETA Mask Network MASK PEAKDEFI PEAK TitanSwap TITAN Sapphire SAPP Venus BTC vBTC Dawn Protocol DAWN Mango Markets MNGO Orion Protocol ORN Chia Network XCH Beyond Protocol BP Ellipsis EPS Bifrost (BFC) BFC Mirror Protocol MIR Radicle RAD Toko Token TKO Request REQ TomoChain TOMO Proton XPR Shiden Network SDN Adventure Gold AGLD RSK Infrastructure Framework RIF MVL MVL Anyswap ANY API3 API3 CRYPTO20 C20 BinaryX BNX Phala Network PHA Linear LINA Dero DERO PlayDapp PLA Standard Tokenization Protocol STPT Uquid Coin UQC Centrifuge CFG QuarkChain QKC Vulcan Forged PYR PYR Bloomzed Loyalty Club Ticket BLCT SuperRare RARE Ultra UOS Alchemy Pay ACH Ampleforth AMPL Star Atlas ATLAS SafePal SFP Everipedia IQ Utrust UTK Syntropy NOIA JUST JST Aragon ANT Automata Network ATA Wanchain WAN Wilder World WILD BORA BORA KeeperDAO ROOK IDEX IDEX Morpheus.Network MRPH Alien Worlds TLM AllianceBlock ALBT Venus ETH vETH Rakon RKN DODO DODO Powerledger POWR Sentinel DVPN Strike STRK Sun (New) SUN Hathor HTR Render Token RNDR Humanscape HUM Kin KIN SOLVE SOLVE ARPA Chain ARPA Karura KAR Molecular Future MOF MX Token MX PlatON LAT DFI.Money YFII Travala.com AVA DerivaDAO DDX Clover Finance CLV RSK Smart Bitcoin RBTC Propy PRO sUSD SUSD KardiaChain KAI TROY TROY Chromia CHR Balancer BAL dKargo DKA Star Atlas DAO POLIS Newscrypto NWC USDX [Kava] USDX ZIMBOCASH ZASH BitShares BTS MCO MCO Smooth Love Potion SLP Ethernity Chain ERN Sport and Leisure SNL LCX LCX Venus XVS vXVS Metadium META Oxygen OXY BarnBridge BOND MATH MATH Ampleforth Governance Token FORTH Gitcoin GTC Komodo KMD QuickSwap QUICK Hifi Finance MFT ZB Token ZB Tranchess CHESS Litentry LIT Hxro HXRO ApeSwap Finance BANANA IRISnet IRIS Klever KLV Alpaca Finance ALPACA GlitzKoin GTN Strong STRONG SSV Network SSV LGCY Network LGCY Gemini Dollar GUSD MXC MXC Presearch PRE Solanium SLIM Vai VAI Dvision Network DVI Akropolis AKRO Zenon ZNN Wrapped NCG (Nine Chronicles Gold) WNCG NewYork Exchange NYE Frax Share FXS ankrETH aEth Elitium EUM XSGD XSGD BSCPAD BSCPAD WHALE WHALE Sora XOR Shyft Network SHFT Haven Protocol XHV PARSIQ PRQ TABOO TOKEN TABOO Decentral Games DG RAMP RAMP Firo FIRO CertiK CTK '; $subst = "***"; $result = preg_replace($re, $subst, $str); echo "The result of the substitution is ".$result;

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