Regular Expressions 101

Save & Manage Regex

  • Current Version: 3
  • Save & Share
  • Community Library

Flavor

  • PCRE2 (PHP)
  • ECMAScript (JavaScript)
  • Python
  • Golang
  • Java
  • .NET 7.0 (C#)
  • Rust
  • PCRE (Legacy)
  • Regex Flavor Guide

Function

  • Match
  • Substitution
  • List
  • Unit Tests
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
Processing...

Test String

Code Generator

Generated Code

#include <StringConstants.au3> ; to declare the Constants of StringRegExp #include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate Local $sRegex = "(?:^|(?<=\|))[^|]*\bpresident\b[^|]*(?=\||$)" Local $sString = "{{Redirect|Harvard}} {{pp-move-indef}} {{Use mdy dates|date=August " & @CRLF & _ "2014}} {{pp-semi-blp|small=yes}}{{Infobox university |name = Harvard " & @CRLF & _ "University |image_name = Harvard Wreath Logo 1.svg |image_size = |caption " & @CRLF & _ "= [[Seal (emblem)|Seal]] of Harvard University |latin_name = Universitas " & @CRLF & _ "Harvardiana |motto = ''Veritas''Harvard's ''Veritas'' appears on the " & @CRLF & _ "university's arms; [[Heraldry|heraldically]] speaking, however, a 'motto' " & @CRLF & _ "is a word or phrase displayed on a scroll in conjunction with a shield of " & @CRLF & _ "arms. [https://books.google.com/books?" & @CRLF & _ "id=zkQWZaZqZfUC&pg=PA330&lpg=PA330#v=onepage&q&f=false Since 1692] " & @CRLF & _ "University [[seal (device)|seals]] have borne ''Christo et Ecclesiae'' " & @CRLF & _ "(for Christ and the Church) in this manner, arguably making that phrase " & @CRLF & _ "the university's motto in a heraldic sense. This legend is otherwise not " & @CRLF & _ "in general use today. |established = 1636An appropriation of £400 toward " & @CRLF & _ "a "school or college" was voted on October 28, 1636 (OS), at a meeting " & @CRLF & _ "which convened on September 8 and was adjourned to October 28. Some " & @CRLF & _ "sources consider October 28, 1636 (OS) (November 7, 1636 NS) to be the " & @CRLF & _ "date of founding. Harvard's 1936 tercentenary celebration treated " & @CRLF & _ "September 18 as the founding date, though 1836 bicentennial was " & @CRLF & _ "celebrated on September 8, 1836. Sources: meeting dates, {{cite " & @CRLF & _ "book|first=Josiah|last=Quincy|title=History of Harvard University " & @CRLF & _ "|year=1860 |publisher=Crosby, Nichols, Lee and Co.|location=117 " & @CRLF & _ "Washington Street, Boston}}, [https://books.google.com/books?" & @CRLF & _ "vid=OCLC11636583&id=KynqxH_4lGUC&pg=RA1-PA586&lpg=RA1-PA586 p. 586], "At " & @CRLF & _ "a Court holden September 8th, 1636 and continued by adjournment to the " & @CRLF & _ "28th of the 8th month (October, 1636)... the Court agreed to give £400 " & @CRLF & _ "towards a School or College, whereof £200 to be paid next year...." " & @CRLF & _ "Tercentenary dates: {{cite " & @CRLF & _ "news|url=http://www.time.com/time/" & @CRLF & _ "magazine/printout/0,8816,756722,00.html|date=September 28, " & @CRLF & _ "1936|accessdate=September 8, 2006|work=Time|title=Cambridge Birthday}}: " & @CRLF & _ ""Harvard claims birth on the day the Massachusetts Great and General " & @CRLF & _ "Court convened to authorize its founding. This was Sept. 8, 1637 under " & @CRLF & _ "the Julian calendar. Allowing for the ten-day advance of the Gregorian " & @CRLF & _ "calendar, Tercentenary officials arrived at Sept. 18 as the date for the " & @CRLF & _ "third and last big Day of the celebration;" "on Oct. 28, 1636 ... £400 " & @CRLF & _ "for that 'school or college' [was voted by] the Great and General Court " & @CRLF & _ "of the [[Massachusetts Bay Colony]]." Bicentennial date: {{cite web " & @CRLF & _ "|url=http://www.news.harvard.edu/gazette/2003/10.02/02-" & @CRLF & _ "history.html|publisher=Harvard University|title=Harvard Gazette: This " & @CRLF & _ "Month in Harvard History|date=September 2, 2003 |accessdate=September 15, " & @CRLF & _ "2006|author=Marvin Hightower}}, "Sept. 8, 1836 - Some 1,100 to 1,300 " & @CRLF & _ "alumni flock to Harvard's Bicentennial, at which a professional choir " & @CRLF & _ "premieres "Fair Harvard." ... guest speaker Josiah Quincy Jr., Class of " & @CRLF & _ "1821, makes a motion, unanimously adopted, 'that this assembly of the " & @CRLF & _ "Alumni be adjourned to meet at this place on September 8, 1936.'" " & @CRLF & _ "Tercentary opening of Quincy's sealed package: ''The New York Times,'' " & @CRLF & _ "September 9, 1936, p. 24, "Package Sealed in 1836 Opened at Harvard. It " & @CRLF & _ "Held Letters Written at Bicentenary": "September 8th, 1936: As the first " & @CRLF & _ "formal function in the celebration of Harvard's tercentenary, the Harvard " & @CRLF & _ "Alumni Association witnessed the opening by President Conant of the " & @CRLF & _ "'mysterious' package sealed by President Josiah Quincy at the Harvard " & @CRLF & _ "bicentennial in 1836." |mottoeng = Truth |type = [[Private " & @CRLF & _ "university|Private]] – [[Research]] |calendar = Semester |endowment = " & @CRLF & _ "$36.4 billion{{As of|2014|06|30}}. {{cite web | title = Harvard Endowment " & @CRLF & _ "Earns 15.4% Return for Fiscal 2014| work = The Wall Street Journal | url " & @CRLF & _ "= http://online.wsj.com/articles/harvard-endowment-earns-15-4-return-for-" & @CRLF & _ "fiscal-2014-1411506002 | accessdate=10 October 2014}} |president = [[Drew " & @CRLF & _ "Gilpin Faust]] |students = 21,000{{As of|2014|09|01}}. {{cite web | title " & @CRLF & _ "= Harvard at a Glance| work = Harvard University | url = " & @CRLF & _ "http://www.harvard.edu/harvard-glance | accessdate=27 November 2014}} " & @CRLF & _ "|undergrad = 6,700 |postgrad = 14,500 |staff = |faculty = 4,671{{Cite " & @CRLF & _ "book|last=Office of Institutional Research.|title=Harvard University Fact " & @CRLF & _ "Book|year=2009|chapter=Faculty|url=http:// " & @CRLF & _ "www.provost.harvard.edu/institutional_research/Provost_-_09_18-" & @CRLF & _ "19facuni.pdf}} ("Unduplicated, Paid Instructional Faculty Count: 2,107. " & @CRLF & _ "Unduplicated instructional faculty count is the most appropriate count " & @CRLF & _ "for general reporting purposes.") |city = [[Cambridge, " & @CRLF & _ "Massachusetts|Cambridge]] |state = [[Massachusetts]] |country = United " & @CRLF & _ "States |campus = [[Urban area|Urban]]{{Convert|210|acre|ha}} (Main " & @CRLF & _ "campus){{Convert|21|acre|ha}} (Medical campus)" & @CRLF & _ "{{Convert|360|acre|ha}} (Allston campus)" & @CRLF & _ "{{Convert|4500|acre|ha}} (other holdings) |sports = 42 varsity teams " & @CRLF & _ "|athletics = [[National Collegiate Athletic Association|NCAA]] [[Division " & @CRLF & _ "I (NCAA)|Division I]] – [[Ivy League]] |nickname = [[Harvard Crimson]] " & @CRLF & _ "|colors = {{color box|#A41034}} [[Crimson]]{{cite web|title=Color - " & @CRLF & _ "Identity Guidelines - Harvard Business " & @CRLF & _ "School|url=http://www.hbs.edu/marketing/color.html|publisher=Harvard " & @CRLF & _ "Business School|accessdate=26 September 2014}} |free_label = Student " & @CRLF & _ "newspaper |free = ''[[The Harvard Crimson]]'' |affiliations = [[National " & @CRLF & _ "Association of Independent Colleges and Universities|NAICU]]" & @CRLF & _ "[[Association of Independent Colleges and Universities in " & @CRLF & _ "Massachusetts|AICUM]][[Association of American Universities|AAU]]" & @CRLF & _ "[[Universities Research Association|URA]] |website = " & @CRLF & _ "{{URL|http://www.harvard.edu/|Harvard.edu}} |logo = [[File:Harvard " & @CRLF & _ "University logo.PNG|Harvard University logo (with its coat of arms)]] " & @CRLF & _ "|publictransit = [[Harvard (MBTA station)]] }} '''Harvard University''' " & @CRLF & _ "is a [[Private university|private]] [[Ivy League]] [[Doctoral " & @CRLF & _ "university|research university]] in [[Cambridge, " & @CRLF & _ "Massachusetts|Cambridge]], [[Massachusetts]], established in 1636. Its " & @CRLF & _ "history, influence and wealth have made it one of the most prestigious " & @CRLF & _ "universities in the world.{{cite book|title=Making Harvard Modern: The " & @CRLF & _ "Rise of America's " & @CRLF & _ "University|last1=Keller|first1=Morton|last2=Keller" & @CRLF & _ "|first2=Phyllis|publisher=Oxford University Press|isbn=0-19-514457-" & @CRLF & _ "0|quote=Harvard's professional schools... won world prestige of a sort " & @CRLF & _ "rarely seen among social institutions. (...) Harvard's age, wealth, " & @CRLF & _ "quality, and prestige may well shield it from any conceivable " & @CRLF & _ "vicissitudes.|year=2001|pages=463–481}}{{Cite book|title=How Harvard " & @CRLF & _ "Rules: Reason in the Service of Empire|quote=... [Harvard's] tremendous " & @CRLF & _ "institutional power and prestige (...) Within the nation's (arguably) " & @CRLF & _ "most prestigious institution of higher learning ...|chapter=Sexual " & @CRLF & _ "Shakedown|pages=326–336|year=1989|publisher=South End Press|isbn=0-" & @CRLF & _ "89608-284-9|editor1-first=John|last=Spaulding|first=Christina|editor-" & @CRLF & _ "last=Trumpbour}}{{cite web|url=http://www.bloomberg.com/news/2011-03-" & @CRLF & _ "10/harvard-mit-ranked-most-prestigious-universities-study-" & @CRLF & _ "reports.html|title=Harvard, MIT Ranked Most Prestigious Universities, " & @CRLF & _ "Study Reports|author=David Altaner|publisher=Bloomberg|date=March 9, " & @CRLF & _ "2011|accessdate=March 1, 2012}}{{cite book|title=Collier's " & @CRLF & _ "Encyclopedia|publisher=Macmillan Educational Co.|year=1986|quote=Harvard " & @CRLF & _ "University, one of the world's most prestigious institutions of higher " & @CRLF & _ "learning, was founded in Massachusetts in 1636.}}{{cite " & @CRLF & _ "web|last=Newport|first=Frank|title=Harvard Number One University in Eyes " & @CRLF & _ "of Public Stanford and Yale in second " & @CRLF & _ "place|url=http://www.gallup.com/poll/9109/harvard-number-one-university-" & @CRLF & _ "eyes-public.aspx|publisher=Gallup}} Established originally by the " & @CRLF & _ "[[Massachusetts General Court|Massachusetts legislature]] and soon " & @CRLF & _ "thereafter named for [[John Harvard (clergyman)|John Harvard]] (its first " & @CRLF & _ "benefactor), Harvard is the [[Colonial Colleges|United States' oldest " & @CRLF & _ "institution of higher learning]],{{cite book|first1=Frederick " & @CRLF & _ "|last1=Rudolph|title=The American College and " & @CRLF & _ "University|year=1961|page=3|isbn=0-8203-1285-1|publisher=University of " & @CRLF & _ "Georgia Press}} and the [[Harvard Corporation]] (formally, the " & @CRLF & _ "''President and Fellows of Harvard College'')" Local $aArray = StringRegExp($sString, $sRegex, $STR_REGEXPARRAYGLOBALFULLMATCH) Local $aFullArray[0] For $i = 0 To UBound($aArray) -1 _ArrayConcatenate($aFullArray, $aArray[$i]) Next $aArray = $aFullArray ; Present the entire match result _ArrayDisplay($aArray, "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 AutoIt, please visit: https://www.autoitscript.com/autoit3/docs/functions/StringRegExp.htm