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
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
  • Match everything enclosed
    (?:...)
  • Capture everything enclosed
    (...)
  • 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

@"
"
g

Test String

Code Generator

Generated Code

using System; using System.Text.RegularExpressions; public class Example { public static void Main() { string pattern = @"<(h[1-6]){1}(?:.*?)?>(.*?)</h[1-6]>"; string input = @"<h1 sdf asd style=""border-radius:50ox; border-radius:50ox; border-radius:50ox;"" class="" >1. Make sure you apply for an ESTA</h1><div><p></p> <h1 style=""position: relative; bottom: 30px;"" adsasdas >Are you planning to visit the United States? Here are <h4> Relaxation </h4> <h4> Relaxation </h4> <h4> Relaxation </h4> <h4> Relaxation </h4> <h4> Relaxation </h4> 12-31-25 asd 11 Travel Tips for USA</h1> . <img class=""aligncenter wp-image-933"" title= dasd""travel_tips_for_usa"" src=""https://usa-esta.us/wp-content/uploads/2014/10/travel_tips_for_usa1-1024x640.jpg"" alt="" width=""614"" height=""384""> Planning a trip to the USA can be quite exciting! It is useful to get familiar with some local customs. The following tips will introduce you to some very common American habits that might not be familiar to all visitors, especially first timers. The <a style=""asdasd asdasd"" dsdfsdfasdasd>ss</a> States is among the world’s top destinatio<ns for visitors from all over the planet. Last year more than 65 million people visited the country. We can all agree that much of American culture is made familiar to the world through its film, television and music industries. Some common U.S. habits, however, are quite different from what we know, and particularly from what we are used to in our country of origin. Most visitors can enter the United States with an <a href=""https://usa-esta.us"">electronic travel authorization</a>. If you plan a holiday shorter than 90 days, for pleasure, <h4ssdad a d style='sadasdasd"" dsfsdfsdf > Relaxation </h4> adasasd <ul style=""color:indianred; font:22px arial;""> <li>asdasdasd</li> <li>asdasdasd</li> <li>asdasdasd</li> <li>asdasdasd</li> </ul> <img class=""size-medium wp-image-921 alignright"" title=""electronic_travel_authorization"" src=""https://usa-esta.us/wp-content/uploads/2014/10/electronic_travel_authorization-300x187.jpg"" alt="" width=""300"" height=""187""> business or transit, a formal visa is not required if your country of citizenship is included in the <a href=""https://usa-esta.us/visa-waiver-program/"">Visa Waiver Program</a>. Although it is generally advised to apply 3 days prior to your departure, we suggest you to apply for your Esta before you reserve your flight and/or hotel.The procedure costs <strong>$72.00</strong>, payable with credit card or Paypal, and is fully carried out online. An Esta is valid for 2 years from the issuance date and allows you multiple entrances. Esta simplifies your travel and formalities upon your arrival to the U.S. <h5> 2. Your final bill is more than expected</h5> <img class="" wp-image-922 alignright"" title=""esta_bill"" src=""https://usa-esta.us/wp-content/uploads/2014/10/esta_bill.jpg"" alt="" width=""150"" height=""134""> <div> <h5>It is generally known that U.S. prices for goods and food on average are quite reasonable. Especially if compared with those in the Euro zone.</h5> &nbsp; <h2>3. Humor is not welcomed at security in the qwdqwdairport</h2> One of the things that might surprise you is that thevwdq price you see shown is not the final price you will pay. For clothing or goods in general, the price usually does not include sales taxes (on average 7%). At many restaurants you will not only have to account for the sales tax, but a minimum of 15% for tips as well. <img class=""size-medium wp-image-923 alignright"" title=""humor_esta_travel"" src=""https://usa-esta.us/wp-content/uploads/2014/10/humor_esta_travel-300x161.jpg"" alt="" width=""300"" height=""161"">While a joke can seem like a good way to alleviate the tension during your security check at the airport, it may very well land you in trouble. Security officers at the airport are friendly, but still extremely alert and serious about their duties. Any threatening joke or suspicious attitude can lead to deep security screening. Do not allude to any bomb, weapon or anything dangerous among your belongings, even sarcastically. For an easy security check, we recommend you leave your humor behind and simply be straightforward with any question you are asked by any security or immigration officer. <a href=""https://usa-esta.us/preparing-to-the-arrival-to-usa/"">For more details on security screening upon your arrival in the USA, visit this section.</a> </div> <div> <h2>4. Have some cash available for tips</h2> We know how frustrating it can be having to hand one-dollar bills to tip to your taxi driver rather than your concierge at the hotel. But as the saying goes, when in Rome do as the romans do! This also holds true in the USA. Many workers in the service industry rely on tips for their income and it is therefor the norm to tip any service provider. Many restaurants, especially those in tourist hubs, automatically add up to 18% tip to the bill. <img class=""size-medium wp-image-924 alignright"" title=""dolar"" src=""https://usa-esta.us/wp-content/uploads/2014/10/dolar-300x225.jpg"" alt="" width=""300"" height=""225"">While in the USA the most common way to pay is by credit card (accepted even for the smallest bill amounts), for small “thank you” tips we suggest having a few dollar bills handy.Tip disclaimers are often found at the bottom of a restaurant’s menu, so be sure to check! Any included tip will also be shown on your bill. If service was exceptional it is sometimes common to add an additional tip to the one already included, but it is not required. <h2>5. Even “in transit” passengers clear customs and immigration</h2> If you are heading from Europe or Asia to some exotic island in the Caribbean or Argentina, chances are your flight will make a stop in the USA. Miami, for example, is the flight Hub for South America. If this is your case, you are what is known as an “in transit” passenger. But don’t be fooled, unlike the majority of other places, American authorities will welcome you like any other visitor. You will have to clear <img class=""size-medium wp-image-925 alignright"" title=""transit_usa_Esta"" src=""https://usa-esta.us/wp-content/uploads/2014/10/transit_usa_Esta-300x130.jpg"" alt="" width=""300"" height=""130"">customs and immigration before boarding your next flight to your final destination. We suggest making sure you have at least a 2 hour layover before your next flight, and even when you are in transit you have to obtain an ESTA Authorization prior to boarding. <h2>6. What to expect at the security control</h2> While clearing security before approaching your boarding gate you will have to: <img class=""size-medium wp-image-926 alignright"" title=""security_tips_for_usa"" src=""https://usa-esta.us/wp-content/uploads/2014/10/security_tips_for_usa-300x217.jpg"" alt="" width=""300"" height=""217""> <ul> <li>Remove your shoes and place them in the scanning machine</li> <li>Remove your laptop, tablet or any electronic device from your bag and have it scanned as well</li> <li>Make sure your electronic devices have enough power in case the officer asks you to turn it on</li> <li>Go through a full body scan. National and international travelers will be scanned</li> </ul> While this last point has raised questions about invasion of privacy, it makes controls a lot quicker. If you have any health concerns, announce it to the officer before going through the body scanner. But remember, you can’t refuse it. <h2>7. Look at the departures screens</h2> Your flight will only be announced at the boarding gate. Given the size of an average U.S. airport, you may not be able to hear the call if you are at the bar or shopping around. So, check your boarding time at the screen, note it on your boarding pass, and remember to get to the boarding gate on time. <img class=""aligncenter size-medium wp-image-927"" title=""departures_tips"" src=""https://usa-esta.us/wp-content/uploads/2014/10/departures_tips-300x197.jpg"" alt="" width=""300"" height=""197""> <h2>8. Concerns about your luggage security? A TSA lock can help</h2> Unlike other countries flight regulations, USA TSA (transport security agency) has banned locks on luggage. <img class=""size-medium wp-image-928 alignright"" title=""tsa_lock"" src=""https://usa-esta.us/wp-content/uploads/2014/10/tsa_lock-300x300.jpg"" alt="" width=""300"" height=""300"">In fact, they randomly open boarded items if any suspicions arise. If you are concerned about the security of your personal belongings you still have an option, use a TSA lock. Besides opening through the number combination, this lock has a unique key TSA possess. There are many pieces of luggage on the market that include a TSA lock. This option, along with the ESTA travel authorization, has been implemented to speed up immigration and security controls. &nbsp; <h2>9. International phone rates are expensive</h2> <img class=""size-medium wp-image-929 alignright"" title=""phones_tips_for_usa"" src=""https://usa-esta.us/wp-content/uploads/2014/10/phones_tips_for_usa-300x171.jpg"" alt="" width=""300"" height=""171"">The majority of businesses and hotels in the USA offer free Wi-Fi to their customers. As a rule of thumb, it is wise to use it when your phone is on. As in any foreign country, using your phone abroad through international roaming can result in an unpleasant bill when back home. Some hotels may charge for the use of their Wi-Fi network. <h2>10. Planning to see multiple cities?</h2> <img class=""size-medium wp-image-930 alignright"" title=""cities_eeuu"" src=""https://usa-esta.us/wp-content/uploads/2014/10/cities_eeuu-300x235.jpg"" alt="" width=""300"" height=""235"">If you are going to travel within the United States, we recommend that you avoid buses. America is geographically large, so the distances to cover are humongous. Buses are slow and uncomfortable. Better options include flights planned well in advanced (the fare is usually very accessible), or renting a car. Even car rentals can be inexpensive if planned in advance. Through online travel websites you can rent a car as low as $ 15 per day. And USA authorities accept your national driver’s license (with few exceptions) while you are within the country as a tourist. <h2>11. Travel insurance</h2> <img class=""size-medium wp-image-931 alignright"" title=""insurance_tipis"" src=""https://usa-esta.us/wp-content/uploads/2014/10/insurance_tipis-300x167.jpg"" alt="" width=""300"" height=""167"">Remember that your country’s <a href=""usa-esta.us/us-health-care-system/"">medical insurance</a> won’t work in the USA. If something were to happen, the entire cost would be your responsibility and medical bills in the U.S. can be very expensive. We advise you to evaluate the option of buying a travel insurance that will cover your health,"; foreach (Match m in Regex.Matches(input, pattern)) { Console.WriteLine("'{0}' found at index {1}.", m.Value, m.Index); } } }

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 C#, please visit: https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex(v=vs.110).aspx