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
No Match

r"
"
gm

Test String

Code Generator

Generated Code

re = /<Buyer>[\s\S]+?<UserID>([^<]+)<\/UserID>/m str = '<?xml version="1.0" encoding="UTF-8"?> <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <soapenv:Header> <ebl:RequesterCredentials soapenv:mustUnderstand="0" xmlns:ebl="urn:ebay:apis:eBLBaseComponents" xmlns:ns="urn:ebay:apis:eBLBaseComponents"> <ebl:NotificationSignature xmlns:ebl="urn:ebay:apis:eBLBaseComponents">eVkp8yKqOGGl6b03ezOglA==</ebl:NotificationSignature> </ebl:RequesterCredentials> </soapenv:Header> <soapenv:Body> <GetItemTransactionsResponse xmlns="urn:ebay:apis:eBLBaseComponents"> <Timestamp>2018-11-06T07:14:02.377Z</Timestamp> <Ack>Success</Ack> <CorrelationID>1495072616792</CorrelationID> <Version>1083</Version> <Build>E1083_INTL_APIXO_18856824_R1</Build> <NotificationEventName>AuctionCheckoutComplete</NotificationEventName> <RecipientUserID>oz.sunshine</RecipientUserID> <EIASToken>nY+sHZ2PrBmdj6wVnY+sEZ2PrA2dj6AElYKhC5eKqQWdj6x9nY+seQ==</EIASToken> <PaginationResult> <TotalNumberOfPages>1</TotalNumberOfPages> <TotalNumberOfEntries>1</TotalNumberOfEntries> </PaginationResult> <HasMoreTransactions>false</HasMoreTransactions> <TransactionsPerPage>100</TransactionsPerPage> <PageNumber>1</PageNumber> <ReturnedTransactionCountActual>1</ReturnedTransactionCountActual> <Item> <ApplicationData>ic6d9i844054605431312608388a</ApplicationData> <AutoPay>false</AutoPay> <BuyItNowPrice currencyID="AUD">0.0</BuyItNowPrice> <Currency>AUD</Currency> <ItemID>222203266767</ItemID> <ListingDetails> <StartTime>2016-07-29T13:10:54.000Z</StartTime> <EndTime>2018-11-16T13:10:54.000Z</EndTime> <ViewItemURL>http://cgi.ebay.com.au/ws/eBayISAPI.dll?ViewItem&amp;Item=222203266767</ViewItemURL> <ViewItemURLForNaturalSearch>http://cgi.ebay.com.au/2018-NEW-Toilet-Bidet-Seat-Spray-Hygeian-Water-Clean-Unisex-Bathroom-Shattaf-AU?item=222203266767&amp;category=0&amp;cmd=ViewItem</ViewItemURLForNaturalSearch> </ListingDetails> <ListingType>FixedPriceItem</ListingType> <PaymentMethods>MoneyXferAccepted</PaymentMethods> <PaymentMethods>PayPal</PaymentMethods> <PaymentMethods>VisaMC</PaymentMethods> <PrimaryCategory> <CategoryID>101405</CategoryID> </PrimaryCategory> <PrivateListing>true</PrivateListing> <Quantity>2142</Quantity> <SecondaryCategory> <CategoryID>0</CategoryID> </SecondaryCategory> <Seller> <AboutMePage>false</AboutMePage> <EIASToken>nY+sHZ2PrBmdj6wVnY+sEZ2PrA2dj6AElYKhC5eKqQWdj6x9nY+seQ==</EIASToken> <Email>oz-sunshine@elifeonline.com.au</Email> <FeedbackScore>17305</FeedbackScore> <PositiveFeedbackPercent>99.5</PositiveFeedbackPercent> <FeedbackPrivate>false</FeedbackPrivate> <FeedbackRatingStar>YellowShooting</FeedbackRatingStar> <IDVerified>false</IDVerified> <eBayGoodStanding>true</eBayGoodStanding> <NewUser>false</NewUser> <RegistrationDate>2011-02-27T09:05:29.000Z</RegistrationDate> <Site>Australia</Site> <Status>Confirmed</Status> <UserID>oz.sunshine</UserID> <UserIDChanged>false</UserIDChanged> <UserIDLastChanged>2016-03-01T00:38:25.000Z</UserIDLastChanged> <VATStatus>VATExempt</VATStatus> <SellerInfo> <AllowPaymentEdit>true</AllowPaymentEdit> <CheckoutEnabled>true</CheckoutEnabled> <CIPBankAccountStored>false</CIPBankAccountStored> <GoodStanding>true</GoodStanding> <LiveAuctionAuthorized>false</LiveAuctionAuthorized> <MerchandizingPref>OptIn</MerchandizingPref> <QualifiesForB2BVAT>false</QualifiesForB2BVAT> <StoreOwner>true</StoreOwner> <StoreURL>http://stores.ebay.com.au/shopelife</StoreURL> <SafePaymentExempt>false</SafePaymentExempt> <TopRatedSeller>true</TopRatedSeller> </SellerInfo> </Seller> <SellingStatus> <ConvertedCurrentPrice currencyID="AUD">24.74</ConvertedCurrentPrice> <CurrentPrice currencyID="AUD">24.74</CurrentPrice> <QuantitySold>2074</QuantitySold> <ListingStatus>Active</ListingStatus> </SellingStatus> <Site>Australia</Site> <StartPrice currencyID="AUD">24.74</StartPrice> <Title>2018 NEW Toilet Bidet Seat Spray Hygeian Water Clean Unisex Bathroom Shattaf AU</Title> <GetItFast>false</GetItFast> <SKU>FAZ0181008AU</SKU> <IntegratedMerchantCreditCardEnabled>false</IntegratedMerchantCreditCardEnabled> <ConditionID>1000</ConditionID> <ConditionDisplayName>Brand New</ConditionDisplayName> </Item> <TransactionArray> <Transaction> <AmountPaid currencyID="AUD">26.74</AmountPaid> <AdjustmentAmount currencyID="AUD">0.0</AdjustmentAmount> <ConvertedAdjustmentAmount currencyID="AUD">0.0</ConvertedAdjustmentAmount> <Buyer> <AboutMePage>false</AboutMePage> <EIASToken>nY+sHZ2PrBmdj6wVnY+sEZ2PrA2dj6wNloajDJCLqQ6dj6x9nY+seQ==</EIASToken> <Email>rany_morcos@hotmail.com</Email> <FeedbackScore>72</FeedbackScore> <PositiveFeedbackPercent>100.0</PositiveFeedbackPercent> <FeedbackPrivate>false</FeedbackPrivate> <FeedbackRatingStar>Blue</FeedbackRatingStar> <IDVerified>false</IDVerified> <eBayGoodStanding>true</eBayGoodStanding> <NewUser>false</NewUser> <RegistrationDate>2009-09-15T09:57:47.000Z</RegistrationDate> <Site>Australia</Site> <Status>Confirmed</Status> <UserID>ranoon1</UserID> <UserIDChanged>false</UserIDChanged> <UserIDLastChanged>2009-09-15T09:57:46.000Z</UserIDLastChanged> <VATStatus>VATTax</VATStatus> <BuyerInfo> <ShippingAddress> <Name>Rany Morcos</Name> <Street1>6/303 maroondah highway</Street1> <CityName>Croydon North</CityName> <StateOrProvince>Victoria</StateOrProvince> <Country>AU</Country> <CountryName>Australia</CountryName> <Phone>0450076244</Phone> <PostalCode>3136</PostalCode> <AddressID>6616753013013</AddressID> <AddressOwner>eBay</AddressOwner> <AddressUsage>DefaultShipping</AddressUsage> </ShippingAddress> </BuyerInfo> <UserAnonymized>false</UserAnonymized> <StaticAlias>ranoon_dy3756phf@members.ebay.com.au</StaticAlias> </Buyer> <ShippingDetails> <ChangePaymentInstructions>true</ChangePaymentInstructions> <PaymentEdited>true</PaymentEdited> <PaymentInstructions>Methods of payment we accept:1. All major Credit Cards through Paypal.</PaymentInstructions> <SalesTax> <SalesTaxPercent>0.0</SalesTaxPercent> <ShippingIncludedInTax>false</ShippingIncludedInTax> <SalesTaxAmount currencyID="AUD">0.0</SalesTaxAmount> </SalesTax> <ShippingServiceOptions> <ShippingService>AU_Regular</ShippingService> <ShippingServiceCost currencyID="AUD">0.0</ShippingServiceCost> <ShippingServiceAdditionalCost currencyID="AUD">0.0</ShippingServiceAdditionalCost> <ShippingServicePriority>1</ShippingServicePriority> <ExpeditedService>false</ExpeditedService> <ShippingTimeMin>2</ShippingTimeMin> <ShippingTimeMax>6</ShippingTimeMax> </ShippingServiceOptions> <ShippingServiceOptions> <ShippingService>AU_RegularParcelWithTracking</ShippingService> <ShippingServiceCost currencyID="AUD">2.0</ShippingServiceCost> <ShippingServiceAdditionalCost currencyID="AUD">0.0</ShippingServiceAdditionalCost> <ShippingServicePriority>2</ShippingServicePriority> <ExpeditedService>false</ExpeditedService> <ShippingTimeMin>2</ShippingTimeMin> <ShippingTimeMax>6</ShippingTimeMax> </ShippingServiceOptions> <ShippingServiceOptions> <ShippingService>AU_Express</ShippingService> <ShippingServiceCost currencyID="AUD">100.0</ShippingServiceCost> <ShippingServiceAdditionalCost currencyID="AUD">0.0</ShippingServiceAdditionalCost> <ShippingServicePriority>3</ShippingServicePriority> <ExpeditedService>true</ExpeditedService> <ShippingTimeMin>1</ShippingTimeMin> <ShippingTimeMax>3</ShippingTimeMax> </ShippingServiceOptions> <InternationalShippingServiceOption> <ShippingService>AU_AirMailInternational</ShippingService> <ShippingServiceCost currencyID="AUD">25.0</ShippingServiceCost> <ShippingServiceAdditionalCost currencyID="AUD">0.0</ShippingServiceAdditionalCost> <ShippingServicePriority>1</ShippingServicePriority> <ShipToLocation>NZ</ShipToLocation> </InternationalShippingServiceOption> <ShippingType>Flat</ShippingType> <SellingManagerSalesRecordNumber>59381</SellingManagerSalesRecordNumber> <ThirdPartyCheckout>false</ThirdPartyCheckout> <TaxTable/> <GetItFast>false</GetItFast> <ExcludeShipToLocation>Africa</ExcludeShipToLocation> <ExcludeShipToLocation>Asia</ExcludeShipToLocation> <ExcludeShipToLocation>Central America and Caribbean</ExcludeShipToLocation> <ExcludeShipToLocation>Europe</ExcludeShipToLocation> <ExcludeShipToLocation>Middle East</ExcludeShipToLocation> <ExcludeShipToLocation>North America</ExcludeShipToLocation> <ExcludeShipToLocation>Southeast Asia</ExcludeShipToLocation> <ExcludeShipToLocation>South America</ExcludeShipToLocation> <ExcludeShipToLocation>AS</ExcludeShipToLocation> <ExcludeShipToLocation>CK</ExcludeShipToLocation> <ExcludeShipToLocation>FJ</ExcludeShipToLocation> <ExcludeShipToLocation>PF</ExcludeShipToLocation> <ExcludeShipToLocation>GU</ExcludeShipToLocation> <ExcludeShipToLocation>KI</ExcludeShipToLocation> <ExcludeShipToLocation>MH</ExcludeShipToLocation> <ExcludeShipToLocation>FM</ExcludeShipToLocation> <ExcludeShipToLocation>NR</ExcludeShipToLocation> <ExcludeShipToLocation>NC</ExcludeShipToLocation> <ExcludeShipToLocation>NU</ExcludeShipToLocation> <ExcludeShipToLocation>PW</ExcludeShipToLocation> <ExcludeShipToLocation>PG</ExcludeShipToLocation> <ExcludeShipToLocation>SB</ExcludeShipToLocation> <ExcludeShipToLocation>TO</ExcludeShipToLocation> <ExcludeShipToLocation>TV</ExcludeShipToLocation> <ExcludeShipToLocation>VU</ExcludeShipToLocation> </ShippingDetails> <ConvertedAmountPaid currencyID="AUD">26.74</ConvertedAmountPaid> <ConvertedTransactionPrice currencyID="AUD">24.74</ConvertedTransactionPrice> <CreatedDate>2018-11-06T07:13:02.000Z</CreatedDate> <DepositType>None</DepositType> <QuantityPurchased>1</QuantityPurchased> <Status> <eBayPaymentStatus>NoPaymentFailure</eBayPaymentStatus> <CheckoutStatus>CheckoutComplete</CheckoutStatus> <LastTimeModified>2018-11-06T07:14:01.000Z</LastTimeModified> <PaymentMethodUsed>PayPal</PaymentMethodUsed> <CompleteStatus>Complete</CompleteStatus> <BuyerSelectedShipping>true</BuyerSelectedShipping> <PaymentHoldStatus>None</PaymentHoldStatus> <IntegratedMerchantCreditCardEnabled>false</IntegratedMerchantCreditCardEnabled> </Status> <TransactionID>2160627739012</TransactionID> <TransactionPrice currencyID="AUD">24.74</TransactionPrice> <BestOfferSale>false</BestOfferSale> <ExternalTransaction> <ExternalTransactionID>7E2132560L3706829</ExternalTransactionID> <ExternalTransactionTime>2018-11-06T07:14:00.000Z</ExternalTransactionTime> <FeeOrCreditAmount currencyID="AUD">0.59</FeeOrCreditAmount> <PaymentOrRefundAmount currencyID="AUD">26.74</PaymentOrRefundAmount> <ExternalTransactionStatus>Succeeded</ExternalTransactionStatus> </ExternalTransaction> <ShippingServiceSelected> <ShippingService>AU_RegularParcelWithTracking</ShippingService> <ShippingServiceCost currencyID="AUD">2.0</ShippingServiceCost> </ShippingServiceSelected> <BuyerMessage>oz-sunshine@elifeonline.com.au</BuyerMessage> <PaidTime>2018-11-06T07:14:01.000Z</PaidTime> <ContainingOrder> <OrderID>222203266767-2160627739012</OrderID> <OrderStatus>Completed</OrderStatus> </ContainingOrder> <FinalValueFee currencyID="AUD">1.58</FinalValueFee> <TransactionSiteID>Australia</TransactionSiteID> <Platform>eBay</Platform> <PayPalEmailAddress>support@elifeonline.com.au</PayPalEmailAddress> <BuyerGuaranteePrice currencyID="AUD">20000.0</BuyerGuaranteePrice> <ActualShippingCost currencyID="AUD">2.0</ActualShippingCost> <OrderLineItemID>222203266767-2160627739012</OrderLineItemID> <IsMultiLegShipping>false</IsMultiLegShipping> <IntangibleItem>false</IntangibleItem> <MonetaryDetails> <Payments> <Payment> <PaymentStatus>Succeeded</PaymentStatus> <Payer type="eBayUser">ranoon1</Payer> <Payee type="eBayUser">oz.sunshine</Payee> <PaymentTime>2018-11-06T07:14:00.000Z</PaymentTime> <PaymentAmount currencyID="AUD">26.74</PaymentAmount> <ReferenceID type="ExternalTransactionID">7E2132560L3706829</ReferenceID> <FeeOrCreditAmount currencyID="AUD">0.59</FeeOrCreditAmount> </Payment> </Payments> </MonetaryDetails> </Transaction> </TransactionArray> <PayPalPreferred>false</PayPalPreferred> </GetItemTransactionsResponse> </soapenv:Body> </soapenv:Envelope> ' # Print the match result str.scan(re) do |match| puts match.to_s end

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 Ruby, please visit: http://ruby-doc.org/core-2.2.0/Regexp.html