Let's havesomefunwithregularexpressions, so I wanttomatchthewordfund.
But I alsowantthisrejectstobeabletomatchthewordrunsonpond, nonorbun, Basicallyanywordthatendswithyouinandstartswithanotherletter, so I'llchangethisrejectstodot u.
N.
SowhenwerunourReg X andsearchthissentenceforsomethingthatendswithyouin, itshouldfindfun.
Soif I wanttoaddsomeletters, I canput H through s.
Sonowwecanseethisisgoingtomatch a rangeofnumberstwothroughsixandalso a rangeofletters h through s so I candoaneyetomakeitcaseinsensitiveand a G tomatcheveryoccurrenceinthewholestring.
Soinsteadofhavingalltheselettersweregonnagotothezerooccurrenceandnothaveanylettersandtheninwiththis I hearsoit's justgonnabe t I sew a greedymatchwouldbe t i t a n I a lazymatchwouldjustbe t I.
Solet's dothesamethingdownhere.
Wehavethisstringhere, whichis a bitofHTMLwithan H onetag, sometextWinter's comingand a closingeachonetag.
If I runthisnowyou'llseeintheconsole.
It's goingtoreturnthewholething.
Sowe'regonnastartwiththemorethansignhere, andthenwehavethedot, whichis a wildcardcharacter.
Soinsteadofinsteadofgettingthiswholething, whichwaswhichisgreedy, wewanttodo a lazymatchwhereitstartshereandjustendsatthefirstoccurrenceofthisgreaterthansign.
And, oh, ifwehadnothad a numberhereandwejusthadthreecommaandthenothingintheincurlybrace, thenitwouldmatchforaninfinitenumberofoccurrences.
Soitbethree h isthroughaninfinitenumberofages, butwe'lljustleaveatsix.
Here's anotherexamplewithquantities, festivefireswherewe'regoingtomatchfourormoreoftheletter Z.
So I'llputtheletters e andthenthecurlybrackets.
I'llputfourcommaandthentherewillbenothingafterthecommabecause, like I saidbefore, whenyouhavenothingaftertheKama, there's aninfinitenumberthat I couldgoto, soithastobeatleastfour, andthenitcouldbeaninfinitenumberofdisease.
Wecanusequantities, specifyIRStospecifyanexactnumberofmatchesinsteadofjust a lowerandupperbound.
A morepracticaluseoflookaheadistochecktwoormorepatternsinonestring.
Sodownhereinthisexample, we'regoingtouselookheadsinthe P W rejectstomatchpasswordsthataregreaterthanfivecharacterslongandhavetwoconsecutivedigits.
Sofor a greaterthanfivecharacters, we'lldoparentheses.
Andthenit's alwaysgonnastartwith a questionmarkequalsifit's a positivelookaheadand I wantgreaterthanfivecharacters, soslash W wouldbeallnumbersandlettercharacters, andwewanttheretobefivecharacters, atleastfivecharacters, andthenwealsowanttoconsecutivedigits.
So I'm goingtomakeanotherlookaheadquestionmarkequals, andwe'regonnasaytherecouldbeanynumberofcharactersthatarenotdigits.
ThisCapital B theslashCapital B is, ah, character.
That's not a digits, andthegastricmeansthey'rezeroormorecatchersthatair.
Not a digit, butwealsowanttomakesurethattherearetwoormoredigits.
Sowehavetheslash D tosaythatthey'regonnabedigits, andthenwehavetositmetwoormoredigits.
Sodownherewe'regoingtoattempttousecapturegroupstomatchnumbersthatareappearedonLeethreetimesin a stringeachseparatedby a space.
WewantthisReg X tomatchsomethinglikethis.
42.
Space 42 Space 42.
Wewouldalsowanttomatchsomethinglike 1 36 space 136 space 1 36 Itdoesn't matterwhatthenumberis, andweonLeewenttomatch a groupofthree, sowedon't wanttomatchfournumbers.
Findnumber 600 just a groupofthreenumbersseparatedbyspaces.
Solet's seehowtodothat.
We'regoingtouse a capturegroup, so I'm goingtoput a parenthesesslash D plusthatmeananynumberofdigitsandthat's gonnabetheendofourcapturegroup.
Andthenit's goingtohave a space, andthen I'm gonnaputslashone, whichjustis a shorthandwayofrepeatingthefirstthinginparentheses, whichisthisandthenwe'llhaveanotherspaceinanotherslashone.
Sothisisgoingtolookforanynumberin a space, anynumberin a space, anynumber.
Soit's thenumberthreetimes.
We'renotquitedoneyet, though, becauseremember, I saysaidWewanttomatchonLeethreenumbers.
Butwehavetowrite a regularexpressionthat's goingtofigureoutwhatwe'regonnareplace.
Well, let's write a regularexpressionthatfindsallthespaceatthebeginningandallthespaceattheend.
Sothisishowwe'lldothistofindeverythingatthebeginningisgoingtostartwith a carrotwhichfindssomethingatthebeginningof a stringandwillputslash s whichisallthewhitespaceandtheanynumberofwhitespacecharacterswilldo a plus.
Nowwealsowanttofindallthespaceoftheend.
So I'lldo a pipecharacter, whichmeansorsoallthespaceofthebeginningorallthespaceattheendforallthespaceoftheendwilldoslash s plusandthen a dollarsign, whichmeansthishastobeattheend.