This free regular expression tester lets you test your regular expressions against any entry of your choice and clearly highlights all matches. Using this, we ...
10RegExTesterforJavaScript,Python,PHP,Golang,Ruby,etc.
By
AsadAli
in
Development
onApril22,2022
Geekflareissupportedbyouraudience.Wemayearnaffiliatecommissionsfrombuyinglinksonthissite.
RegExTesters
Regex101
FreeFormatter
RegexCrossword
RegExr
Pythex
Rubular
Debuggex
ExtendsClass
RegExTester
WebToolKit
InvictiWebApplicationSecurityScanner-theonlysolutionthatdeliversautomaticverificationofvulnerabilitieswithProof-BasedScanning™.
Regexexpressioncanbeapain.Well,sometimes!
Let’slearnaboutRegularExpressionsandtheirpatterns.Wearegoingtolookintosuchpatternsthatseemlikeaconvolutedsoupofcharacters.Wewillseewhateverycharacterinaregularexpressionmeans.
Afterreadingthisarticle,youwillbeabletocreateyourregularexpressionsandusethemforasyoulike.Intheend,wewillalsolistdownsomeoftheonlineRegExtestingtoolssothatbasedonrequirementyoucancreateyourRegExandtestitusingthesetools.
Introduction
RegularExpressionsorasit’scommonlyknown–RegExisanysequenceofcharactersthatcanbeusedasapatterntosearchforcharactersorstrings.
Forexample–todetermineifastringorphrasecontainstheword“apple”wecanusetheregex“/apple”tosearchwithinthestring.Asanotherexample,wecanuse“/[0-9]”tocheckifagivenstringcontainsanumberbetween0and9.
RegularExpressionsandtheiruse
Regularexpressionsarewidelyusedforavarietyofpurposesinmodern-dayweb-relatedoperations.Validationofwebforms,Websearchengines,lexicalanalyzersinIDE’s,texteditors,anddocumenteditorsareamongafewexampleswhereregularexpressionsarefrequentlyused.
Wehaveallused“CTRL+F”manytimestosearchwithinadocumentorapieceofcodetofindaparticularwordoraphraseoranexpression.Thisoperationcanbepointedoutasaverycommonexampleoftheuseofregularexpressions.
Beforegoingonanyfurther,let’shavealookataverycommonlyusedregularexpression.
Canyouguess🤔thebelowRegEXwhatisitusedfor?
^([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5})$
Don’tworryifyoucan’tguessit.Iamdamsureyouwouldbeabletoguessbytheendofthisarticle.
Firstlet’sgetstartedwithA,B,CofRegEx.
Tokens
Tostartwith,let’slookatthevarioussymbolsintheRegexshownabove.
^([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5})$
Ifwelookattheregexgivenabove,wecanseethatiscomposedofmanysymbolsorcharactersortokens.Let’sfindoutwhattheymean:
Token
Meaning
^
Thistokendenotesthestartofastring.
(…)
Thisdenotesagroupwhereeverythingthatisgivenwithin(…)iscaptured.
[…]
The[]enclosescharactersanyofwhichcanbematched.Forexample–[abc]willmatcheitheraorborc.
a-z
Thesetoflowercasealphabetsfromatoz.WemustkeepinmindthatRegexiscasesensitive.
A-Z
ThesetofuppercasecharactersfromAtoZ.
0-9
Thedigitsfrom0to9.
_
Thiswillmatchthecharacter_.
\
Thisistheescapecharacter.
\.
Thismatchesthecharacter“.”literally.Thisisusedbecausethesymbol“.”inregexisatokeninitselfwhichmatchesanycharacter
+
Thisisaquantifier.Thismatchesoneormorecharactersitisusedwith.Forexample,a+meansoneormoreoccurrencesofthecharactera.
\-
Thiswillmatchthe“-”character.
@
Thiswillmatchthe“@”character.
{}
Thisisanotherquantifier.Itisusedtodenotethenumberofoccurrencesofacharacter.Forexample,a{3}meansexactly3a’s.
$
Thisdenotestheendofastring.
BreakdownofthegivenRegexpattern
Now,armedwiththispreliminaryknowledgeoftokens,let’strytodecodetheaboveregularexpression:
^([a-zA-Z0-9_\-\.]+)meanswearelookingforastringthatstartswithatleastoneormoreuppercaseorlowercasealphanumericcharacters,underscores,hyphens,ordots.Forinstance,anythingthatlookssimilartouser_name.01willmatchthepattern.Wemustrememberthatheredon’tneedtoincludeallthesymbolsjustanyonecharacterin[a-zA-Z0-9_\-\.]willdo.The@charactermatchesforasingleoccurrenceof@.Addingtothepreviousexample,somethinglike[email protected]willfit.([a-zA-Z0-9_\-\.]+) issimilartothefirstpoint.Ittoomeansthatwearelookingforastringthatcontainsatleastoneormorealphanumericcharacters,underscores,hyphens,ordots.Addingtotheexample,[email protected]willfithere.Asyoumighthavealreadyguessed,wearehintingatanemailpattern.Movingon,\.matchesthesingle“.”character.Ifwecontinuewiththeongoingexample,somethinglike[email protected]([a-zA-Z]{2,5})$thismeansthatthestringshouldendwith2to5alphabetcharacterseitheruppercaseorlowercase.Ifweadd.comtothepreviousexample,wecanget[email protected],whichisthecommonpatternofanemailstring.
Combiningalloftheabove,wecanseethatwearesearchingforanemailidstring.Nowwecanusethisexpressiontovalidateanyemailid.Ifourtestemailidmatchesthispatternwecansayitisavalidemailid.
P.S.–Thisapatternformostcommonemailidsontheweb.
TypesofTokens
ManytokenscanbeusedinvariouscombinationswithinaRegextodescribeawidevarietyofexpressions.Belowwearegoingtotakealookatthevarioustypesoftokensthatareusedinregularexpressions.Furthermore,wearealsogoingtolookatthemostcommonlyusedtokensineachcategory.
BasicTokens
Let’sstartwiththebasictokens.Thesetokensareusedwithalmosteveryregularexpression.Hence,wemustlearnaboutthemfirst.
Token
Meaning
\r
Thismatchesthecarriagereturncharacter.
\0
Itmatchesthenullcharacter.
\n
Thislooksforanewline.
\t
Thismatchesforatab.
Characterclasses
Movingon,let’slookatthecharactertokens.Theyareusedtomatchalphabets,numbersandotherspecialcharacters.
Token
Meaning
a
Thismatchesliterallyforthecharactera.Similarly,allalphabetsandnumberswhenusedinisolationlookforthespecificcharacteritself.
abc
Itmatchesthestringabc.
[abc]
Thislooksforasinglecharacteramonga,borc.
[^abc]
Thismatchesanycharacterexceptaorborc.
[a-z]
Alowercasecharacterintherangefromatoz
[^a-z]
Anycharacternotintherangefromatoz.Thisincludesuppercasecharactersaswell.
[A-Z]
AnuppercasecharacterbetweenAandZ.
[^A-Z]
AcharacternotbetweenAandZ.
[0-9]
Anynumberintherange0to9
[^0-9]
Acharacternotintherange0to9
[a-zA-Z0-9]
ThismatchesforacharacterwhichmaybealowercasecharacterfrombetweenaandzoranycharacterbetweenAandZoranynumberbetween0and9
[^a-zA-Z0-9]
Anycharacterthatdoesn’tfallinthepreviouscategory.
.
Anysinglecharacter
\s
Thisisusedtolookforanywhitespacecharacter.
\S
Thisisusedtolookforanynon-whitespacecharacter.
\d
Thismatchesforanydigit
\D
Thismatchesforanynon-digit
\w
Itmatchesanywordcharacter
\W
Itmatchesanynon-wordcharacter
$
Thisdenotestheendofastring
\b
Thismatchesawordboundary
\B
Thisisusedtomatchanon-wordboundary
Quantifiers
Thisspecialclassoftokensisusedtomatchthenumberofconsecutiveoccurrencesofacharacterorastringoranumber.Theyareusedinconjunctionwiththeothertokens.
Let’slookatafewcommonquantifiers.
Tokens
Meaning
a?
Thismatchesforzerooroneoccurrenceofa.
a*
Thismatchesforzeroormoreoccurrences(consecutive)ofa.
a+
Thisisforatleastoneormoreconsecutiveoccurrencesofa.
a{5}
Thislooksforexactlyfiveconsecutiveoccurrencesofthelettera.
a{5,}
Thisisforatleastfiveormoreconsecutiveoccurrencesofa.
a{5,7}
Thislooksforanynumberofconsecutivea’sbetween5and7.
Groups
Thesetokenswillmatchingroupsasthenamesuggests.
Tokens
Meaning
(…)
Thiscaptureseverythingenclosedwithintheparenthesis.
(a|b)
Thismatcheseitheraorb.
(?:…)
Matcheseverythingenclosedwithinthebrackets
(?(1)yes|no)
Thismatchesaconditionalstatement.
Flags
Thesearespecialinstructionsgiventothepatternmatcherenginewhilesearchingforamatch.
TokensMeaning
g
Globalmatch.Thiswillsearchuntilthematchingenginefindsnomorematch,i.e.,untiltheendofthegivenstringorgroupofstrings.
m
Multilinematchi.e.,linebyline.
x
Tellstheenginetoignorewhitespaceswhilematching.
X
Thisisusedforextendedmatching.
s
Thismatchesasingleline.
i
Thisisusedforcaseinsensitivematching.
u
ForUnicodecharacters.
Anchors
Additionalinstructionsfortheengineregardingpositions.
Tokens
Meaning
^
Thisdenotesthestartofastring
\A
Thistoodenotesthestartofastringaswell
\Z
Thetokenfortheendofastring.
\z
Thetokenforabsoluteendofastring.
\G
Thisisforthestartofamatch.
Commonlyusedregularexpressions
RegularexpressionsarewidelyusedovertheInternet.Fromformvalidationstolookingupdatacontainingaparticularkeywordorkeywords,regularexpressionsarealmostinseparablefrommodern-daycomputingapplications.
Let’slookatsomefamiliarexamplesoftheuseofregularexpressions.
Matchingaphonenumber
Let’sseewhatisthepatternofaphonenumberusedinIndia.TheCountryCodecomesfirst.Itusuallycontainsa“+”characterfollowedbythenumber91,whichisthecountrycodeforIndia.Also,Indianphonenumbersgenerallystartwith6,7,8,or9.Thisisthenfollowedby9otherdigits.
SoavalidregexforanIndiancellphonenumberwouldbeasgiven.
^(\+91[\-\s]?)?[0]?(91)?[6-9]\d{9}$
Testingthestrengthofpasswords
Mostwebsitesrecommendustoprovideastrongpasswordwhichcontainsacombinationofnumbers,uppercaseandlowercasecharacters,andsymbols.Also,therehastobeaminimumnumberofcharacters–6or8.Thisisdonesothatthepasswordbecomesveryhardtocrack.
Anypasswordfollowingthisrulecanbegeneratedorvalidatedforpasswordstrengthusingaregularexpression.
^(((?=.*[a-z])(?=.*[A-Z]))|((?=.*[a-z])(?=.*[0-9]))|((?=.*[A-Z])(?=.*[0-9])))(?=.{6,})
URLMatching
URLsarethemostcommonwaytousetheinternetandquicklyvisitthewebpagewewant.AlmosteverywebsitehasanURL.Hence,everyURLisstandardizedandfollowsadefinitepattern.EveryURLeitherfollowstheHTTPortheHTTPsprotocolfollowedby“://”andthe“www”often.Thenthenameofthewebsitefollowedbya.comor.netor.orgetc.
TotestthevalidityofanURLwecanusearegexliketheonegivenbelow.
https?:\/\/(www\.)?[[email protected]:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)
DateandTimeformats
Dateandtimeformatsarealsoverycommonlyusedacrosstheweb.Therearemanyformatsofdatesusedbyavarietyofapplicationsorsoftwareorsystems.Datesshouldalwaysbeusedinaformatthatmakesitusablefortheuserortheapplicationthatistryingtoreadit.
Adateintheformatdd-MM-yyyycanbevalidatedbyusingaregularexpressionwhichcanbeasgivenbelow.
^(1[0-2]|0[1-9])/(3[01]|[12][0-9]|0[1-9])/[0-9]{4}$
Now,let’sexploresomeoftheonlineRegExtoolswhichcanbehandytobuildandtroubleshoot.
Ifyouwanttolearnmoreaboutregularexpressions,theirexamples,andadvancedusages,hereisalistof websitesthatyoucanalwaysreferto:
Regex101
Regex101isanexcellentreferenceguideandaninteractivetoolforcreatingyourregularexpressions,itcanhelpyougetstartedwithregexveryquickly.
UsingthiswecantestRegExforthebelowlanguages.
PCRE(PHP)ECMAScript(JavaScript)PythonGoLang
ItprovidessupportsforRegExfunctionalitieslikeamatch,substitution,andunittests.ApartfromthisonecansavetheoldtestedRegEx.
FreeFormatter
FreeFormatterisJavaScript-basedandusestheXRegExplibraryforenhancedfeatures.ItfacilitatestestingaRegExagainstamatchaswellasreplacingamatch.Itsupportsbelowflags,whichcanbeuseddependingupontherequirementwhiletestingaRegEx
i–Case-insensitivem–Multilineg–Global(don’tstopatthefirstmatch)s–DotmatchesallINCLUDINGlinebreaks(XRegExponly).
RegexCrossword
IfRegexandpuzzlesinterestyou,thisisthesitetogoto.Ithasaseriesoffunandinteractivepuzzles.Theywilldefinitelyhelpyoulearnmoreaboutregularexpressions.
OptimizedforphonesandsolvingRegExpuzzlesonthego.Astepbysteptutorial,teachingyouthedifferentsymbolsandRegExpatterns.Bendyourmindaroundcubistic2DpalindromeRegExpuzzles.WiderangeofRegExpuzzleswithdifficultiesfrombeginnertoexpert.
RegExr
RegExrisawebsiteforgettingyourhandsdirtywithRegex.Youcanwriteregex,matchpatterns,andhaveallthefunwiththisCodepenequivalentforRegularExpressions.
Features
SupportsJavaScript&PHP/PCRERegEx.Resultsupdateinreal-timeasyoutype.Rolloveramatchorexpressionfordetails.ValidatepatternswithsuitesofTests.Save&shareexpressionswithothers.FullRegExReferencewithhelp&examples.
Pythex
ItisaPython-basedregularexpressiontester.PythexisaquickwaytotestyourPythonregularexpressions.Itcomeswithfourflagsnamely
IgnoreCaseMultilineDotAllVerbose
Rubular
RubularisaRuby-basedregularexpressioneditor.ItsupportsandusestheRuby2.5.7versiononwards.
Debuggex
ItisJavaScript-basedandsupportsRegExforPythonandPerlCompatibleRegularExpressions(PCRE).UsingthisonlinetoolwecanembedourRegExtoStackOverflow.ItprovidesafacilitytosharetheRegExresultbycreatingauniquelinkagainsteachRegExtest.
ExtendsClass
ExtendsClassisatoolboxfordevelopers.ItprovidesRegExtestingsupportforthebelowlanguages.
JavaScriptPython(3.4)Ruby(2.1)Java(JDK14)PHP(7)
RegExTester
Thisfreeregularexpressiontesterletsyoutestyourregularexpressionsagainstanyentryofyourchoiceandclearlyhighlightsallmatches.Usingthis,wecansavetheoldtestedRegExforfuturereference.Moreover,itsupportsJavaScriptandPCRERegEx.
WebToolKit
WebToolkitcontainsasetofutilitytools,RegExtesterisoneofthem.WecaninputourRegExhereandcantestitagainstavalue.Italsoprovidesafacilityforreplacing,matching,andcopyingtheexpressions.Apartfromthis,itprovidesatoggletoperformacase-sensitiveandglobalmatch.
LearningResources
IfyouwishtolearnRegEx,herearesomeofthebestcoursesavailableonline.
Coursera
Courseraoffersinterestingguidedprojectcourseswhichwillgiveyouhands-onexperienceusingRegEx.Mostoftheseprojectcourseslastaboutanhourandyouwillbeworkingstep-by-stepalongwiththeinstructor.HerearesomeofthebestRegExprojects.
RegularExpressionsinPythonExtractTextDatawithJavaandRegExExtractTextDatawithBashandRegEx
Udemy
UdemyoffersaCompleteRegExcourseforbeginnerswhichteachesyouthebasicsin3.5hoursandaPythonRegExCoursewithProjectswhichwillgiveyouhands-onexperienceusingRegExforinputvalidation,dataprocessing,andtransformation.
Conclusion
Welearnedtheregularexpressions,afewcommonexamples,andsomeoftheonlinetestingtools.Withthisknowledge,wecancreateourregularexpressionsandusetheminourapplications.
Enjoyedreadingthearticle?Howaboutsharingwiththeworld?
Taggedin:
JavaScript
PHP
MoregreatreadingsonDevelopment
11DeepLearningSoftwarein2022
AmritaPathakonJune15,2022
Understanding301RedirectsforBeginners
TanishChowdharyonJune14,2022
20FrequentlyAskedDevOpsInterviewQuestionsandAnswers[2022]
TalhaKhalidonJune14,2022
7VimEditorsforBetterProductivityin2022
AshlinJenifaonJune14,2022
AnIntroductionGuidetoAWSFargate
NamanYashonJune14,2022
10Cloud-BasedCrossBrowserTestingTools[2022]
SaptakChaudhurionJune13,2022
JoinGeekflareNewsletter
Everyweekweshare trendingarticles and tools inournewsletter.Morethan10,000peopleenjoyreading,andyouwillloveittoo.
YouremailYouremail...JoinNewsletter
RegExTesters
Regex101
FreeFormatter
RegexCrossword
RegExr
Pythex
Rubular
Debuggex
ExtendsClass
RegExTester
WebToolKit
MoregreatreadingsonDevelopment
11DeepLearningSoftwarein2022
11DeepLearningSoftwarein2022
Understanding301RedirectsforBeginners
Understanding301RedirectsforBeginners
20FrequentlyAskedDevOpsInterviewQuestionsandAnswers[2022]
20FrequentlyAskedDevOpsInterviewQuestionsandAnswers[2022]
7VimEditorsforBetterProductivityin2022
7VimEditorsforBetterProductivityin2022
AnIntroductionGuidetoAWSFargate
AnIntroductionGuidetoAWSFargate
10Cloud-BasedCrossBrowserTestingTools[2022]
10Cloud-BasedCrossBrowserTestingTools[2022]
Thankstooursponsors
PowerYourBusiness
Herearesomeofthetoolsandservicestohelpyourbusinessgrow.
InvictiusestheProof-BasedScanning™toautomaticallyverifytheidentifiedvulnerabilitiesandgenerateactionableresultswithinjusthours.
TryInvicti
Webscraping,residentialproxy,proxymanager,webunlocker,searchenginecrawler,andallyouneedtocollectwebdata.
TryBrightdata
VultrfeaturesthelatestgenerationCPUsandanintuitivecontrolpanel,alongwith100%KVMvirtualization.
TryVultr
Semrushisanall-in-onedigitalmarketingsolutionwithmorethan50toolsinSEO,socialmedia,andcontentmarketing.
TrySemrush
Explore50+resources
Closethismodule
GeekflareNewsletterMorethan10,000peopleenjoyreading,andyouwillloveittoo.EmailEnteryouremailaddressJoinNow