0% found this document useful (0 votes)
4 views19 pages

Java Regex Full Notes

The document provides an overview of Regular Expressions (Regex), explaining their purpose as a sequence of characters that define search patterns for matching and locating specific text. It discusses the utility of Regex in various programming languages, its powerful search capabilities, and the importance of the Matcher class in Java for performing operations on strings. Additionally, it covers various quantifiers and modifiers used in Regex to enhance pattern matching, including examples of phone number and email validation.

Uploaded by

pawaseaditi22
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
4 views19 pages

Java Regex Full Notes

The document provides an overview of Regular Expressions (Regex), explaining their purpose as a sequence of characters that define search patterns for matching and locating specific text. It discusses the utility of Regex in various programming languages, its powerful search capabilities, and the importance of the Matcher class in Java for performing operations on strings. Additionally, it covers various quantifiers and modifiers used in Regex to enhance pattern matching, including examples of phone number and email validation.

Uploaded by

pawaseaditi22
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
_ __* | Regular Expression CRegex) * =| Retex _is_q_shoré_name for: 'Regular Expressions __ =| Remex is a “sequence of char” that defices a sea- [rch pattern G i+ It used to match, locate CF?nd) asd eee ea aan a ee _Specrric _pattern____— pee ROG ox iS Kec powerful seGreh language. for Str~ S$ — erence SS ___2|ReGex> is supported for att Pepe poe axe —____|h_os __Jowa.,J5, Python ere __and_€re patterns _rercains pconsrstent through our Che. tcinguages Wingy we use. fg) Pocten based search = Bee RAY ep hes Eto Ge em oer Seon Ose oh 2 : é See) Replacement > _ Beate ig. po te Peerernleech cee ae = aa oe Ice _Gll__muttiple spaces qth _sengle space exenction = = ——— > Fetch aq _data_ from __a_text. Se Jb Instead of exiting _& _compex logic % feagthy code a using cond"s —Or-loops—,— Regex an match co fene _10_compact & smnge_expresstan.___ } Dote : 3} compose Be Rowenta peers pA sss SE nw iene ee lace dozens of Nimes of PinGrnad “StringnetCheckin ss) abr os oe ete 9} Goss —tanguageSupparesie ——+}Same _ReGiex _fogit__ orks sin ale moast_QiL macem _ Prgrariming languages. A = ——§4i] Feribie i ——___‘| Design for searching & oat Core €_ Quickly ——__+} J€'s useful tn anatsis, dota clean’ 1G, Web sere | bing Form uolidations ,etc =| Te_con_almose _tmaich any pattern [Link] earls, —_ Prone no., dates, IP addresses ete. gar S| stent —e exc pr ok regeons fate 2) as mates 4 erat) ss > - [for using tegen we have to Peoport—javo.u8t regex” package aC besa th 2 Wp blinich_cortains + classeS=—suchos , ———_—__~ | Pattern Mlatcher t wilenaeal 2 oeu ne Date: OF =08-2025 el) eka Pattern class 2 2 AID. youg) -____- | The _pattem closs iS used Compfie: yegex-inte=o! pattern __ ‘ | Ghar can _be_ Ose} _t0_Ffad_matches —_tn_character seq. Sse ns a __] ttern. comeit ee ©) method ), ____-| Tena Matcher is created _asrng = "nate Car ) + poses T | ~eigssName ems = x aa Frame faqs are _modfFiers Used _cahen, peared a. regex pas — 4¢ferm . _ soe Een a —__——=| They Change _the_behoviow OF pattern Pad ee nt | __-|use +4 Roe, fot flags) 3 si Flag Hamre. — pescnigeen il Se a)\Case Insensitive __- Ignores the case, es, L__)|DotwAll + It matches new line. ead | Literal - Tt reat ¢he Regex as Sting pA Miteral, i ‘| Unicade Case 7 It’ used uth Ease_Insensitive, age - which enables Unicdde Characters tS Se ee ng A publics. static. Pattern home. (Serre sveges). =. =} It compres tho ey eee emer ren ee =3 {object we £ fie com “used this. tieronca Pines eee a ae tees” Orm__match operation =3 = ap | Te throws “paweernSyntex Exception te fhe FeQer is fms 3 Loid . =| bg Et — 3 | port java.urii_xegex *5_ Lclass_Peqexéxarnpe t =< psymQ £ eH Pottem _ poten migudede. Say Cpe: = Matcher _motcherd * gottern marche Cobe)s PB matenere > Catccdetghi*): -matthe Si°ssuo Soeieese Concabed*) Soe Cratcner a marthesQ)3 tue fp eer eG a a enna Say Dote : public static Te compries_the segue eeprestin-irngefattermob, Ject _ystng _an_addi¢ional_fiag.—__ renee iboe Hii gs 8 JOenszitve )j San. ins: —| Pntciner _martcner + ee [Link] HLL, Java — Patten comple Cyova", Pattern Cast IN His Gasy*) 5 Ne Latin c ui while Cmarcner sind ©) 1 =. a Sor Cmotcher greupO +" _% "_+ marche star 60 _ * Serercarch@r en dC )) get 23 created by sun "i Pottern pattem = ——_Fattern compile “java” ePatten Case. SENSITIVE); 44 = —MaeCher . maicher * pactern, matcher (ser) 3__ $0? Crain seing +" 45tr) SOP C" regex” spastem eStringQ)>__ hie (matcher . Find 0) £ ers —S9PC matcher. start) + "2" +matcher. end ©) _ = -.“ Fins tmatcner groups); __ [f =3 Octe : Se ection ee ee == oo JLE Creates _G _mnatche Rageiece: el ee —___.-_|-Fo put _against__the_ comprie pattern Sp bps tos is tid = | psumcd) ip s S$ ___String_str = “agcazecHe @sus22* 3 Rin poren* Pattern compe C To-3] sats pee ee Co-9K)s - = = patfern marches Cs) SOP Csr); as se) 4 a e = ap a ertie Cmaterer fred E ———}-_____S©P( eatener. cup O~ “ =f 4°," +morcher ena) 3 ‘s E = Dote : ches the _entive _fnpur Skiing, mn as Te Chrous _pert__ PattemSyntoxException re the a Vovicles ., siete 2 Sin i I SC pol Pa iueno, Jaret oa easing Pend + | WATP_S_valicicure_cs_cumber eed ae ioe pavmOi Hee ce ______| Sop C"enter your contact no. : ie = Sting phone « "+94" + Crew _jove.uKil Scanner System 3 eS tin nexe C))53 pie 1actobiess 908 Sa TE _( Pattern. motches Bait 'pie ot OF ay a 2 bag: _SOPC phone +" Prore Number is Valid 1) 525 3 —— ese f sh + - COFOF eS. SoP( phone +” Phone Number is matic) 5 \ a | public string potter © |3e returns the onigtral regex sting from nich the pattern wos Compiled. Ce ae ! _ Dote : 08-08-2025 === 2] Eg- A s bs = psymo i 3 £ | Pattern pattem > Pattetn .comerie C Ca -91 {13 Co -s “21338 a. SoP (pater) i _ : ____| _ SOP ¢ patter boScing)) 5 ss ae oe} 80 parte. potted) br oe asst 3 2) | Matcher Class + Ho |) 8 =| A_matcher Class in java_is_a part of "java ubitireges* pa =. cisage_ ! wg |S used im perform, eoictcperuton naelenichescs waceer S@- ——__silquence _ Cie. 0. string) using. c+ _com~tied pattern ___- bsobuue. done. need _ce=creake ic, neucher object = directiy — | = aa We crested ee: From ct 4. Pattem Object = sistmg = __+ using eu. keyword, j crores C:Steng_tnputc- Jefe Methods of matcher. Class. 2D |eurlic — tat Eo a enciliomintuastors C) p= es a ey ee SD panic, en Qe oapt2s aS x Dote sae S| public tot _grouptount ©) 3 Rie g io eB: Bap i econ raat a | SP ee ia en eee ___8) public __boolean fied Crt_stare) i 2) public _semg foString C$ OD _ | fea + ———_-Subsequente.. that — metehes the pattern and _orxtoten returns True _9f search bictory String found kor _ —{returns false. —| Zt moves Che search posicion +forword ach time —O | Red Got scared s- Barre a gt Sate). ae wi ; resets _the search to seart from _a_treon_fndex_, | ond tries to fied a imeateh ++ t \ \ 3 a Basis eee =| psymort | Fattern pes Pattern. comptie C Co-3)") | Matcher mt spt. motcher Cscdf iasqerwgsdh?) 3 9p }——Sef Cg Ring 04275 = tt —— G2))5 =I —1— (0); mn iy 3 er mba = [Link] C scési po fie . cutete Cmesernd SoP( [Link]) +7 = +mes- stort) 3 I i u q 3 4 a 3) _| group): 3 fe u =. Ser ee a. Ehe tino Exerg, 4) _| start QO * 1 ———+|This method _returmes the Yast start _fndex ce the Ost _ Pmatch subsequence. __ 3. << £ S) | end ©) * WAS za $+ This_method returns the end _fndex_of the last _mat— i__} Cred _subsequercce. ———— A 00 5 §)| public _vord yesee Cot Seah a. = {This method resets __the Matcher __etther > _the original! a M@p_or mew One. _ a 3 ea 3) er ee me Lt RMN E Ts Z mM | Reatterm pt. + Patera, tesa =2a-2] or Mloaeécher me» [Link] (* abcazak**v ¢6 1178 * | pa _—_— 1b 28 ype Cont. God) Ibaey 35 ep San) Sed ____ Sor [Link] ttm. stave Qs Pe ne enck)s :— ee Ree RE ——E———— ana / DBATIS@aciatitictsm: aeeusime one fof =| In_regex quantifier spectfies hous many times _c7part- a | Feuley pattern should be repeated fo ee ae |g totve constdered aso macned_____ ence A tfegs pase tar" mater “O" “aa? “aoe! =3- Pastern "0923" matcher Ga. = SB) | Revuctant:: Quantieier =|tesir Ore a S4pes_of quantifier 3) | Greedy Quantisier_Crefaule « ee ag + 9)_| Posesstve Quantirier eS Mg) | Greedy_Quaneifier | Te _trfas ta _rnotth as _onany characte- _as= passe bie _sahi- —___| le _ Stl _a\loaeng, pe a ___ Description _ 2ero__.Qr._muttipie Cimes =e One or _muttiple times ___ LSracty aueast times _=| fountej ede t= stan Or gg = -| Yaotid__Numioers + Nuts mbes should Sf Ore _wo Mth 3,8 __] > |Smoid plumbers —_| tes, or string _utth 1 _digie other Dote Yn mk Net between obi) times A % Phone _pumber validation $y ~| mace po = +9 Sip digit_ number) = _ Or 946 10- digic Moo or 8 For mto?le. qumibers, cohich is ___* _ ___ typical in rndia. a es J tag Cam be nos with fener hein iG _ai- gtts _cantciaing: mon. = oumeric’ Churo- awn e _— bran 3/8 or Stir 9 road bl Progrum i we 2 pth = class VaridorionRegex fT _ psum Oto | f4an- array cohich_Contdins_Sample* tese_cases __| "new Strfing (90J5_ Z for CStang—phone_!_proretlumbers) 2 | 1 C phonelMucdoerTs Valid C phone) SOP ( phone); ee ee Dote : a J —___ps+ boolean proreNumberisValid| Gsefng prone) 2 S| Strmg_ regen « “* Wa Gal -) 153 Ce -9) 443 Lo-5] 2° i ee fr or ayes pi 3 = | 3. ead return. Patten. marches (a 0 = r-ore S007 ce ero ¢ J v SJ a oa ts ead La ” 9 digit scape chorecters agit eos == | es paca Maldotion}! gkeibo: cos stews) Sh =4. psrHPoarOor = Cord forrect he eS 12 =digit _ seg) my eines ee ees dashes for better i readarttiey ber cas 3 > Se | Example Volta Rodhoor clumog- = S32}1954 S638 $612 A Cositin spores) es ee AX BA" SORE= OVA __CeniGh clashes) 2 = \Da4SOAFAO(D2 Cno spaces _or_cdoshes) gest 2s ioe ae x Sas EN ; Pag Aa Ci L Tisai - 5 chen \ S escape 2 xs Chavacter chenesctey Vergth “e We) Pan card validation ~| The PA oo. consises 610 _choroeter —___ eae The “first exe: Chovocters. cre clphubetia Cletters)_____ The next tour choracers are cumeric_Cdtgrts) —__—_ee | The last characters _olphobenc.—Clerter) ___________—___, Characters ean x _8cp-71 855 Co = ie} Caz} Ernotl _ID_ varidouion..§. ees See aitocat_pe part _ Se F 2 5 Ree can include letters:,-digits | pcan and_per [+ The part before tre @_symtao|—__ = Nas ons. = =i Lessee: 5 | Baia 2a ea ainnna aA : 2| Domcia eats = af: Re |e mis part acter. re @ syentio} CES domain | rames — es Bites ont | top-level Domain a Bas + A TRS _ pot _atter_ ee pericd 0), oshich_insicates fro dormain _caregory - ] egies ree eee | reese f Wcla-20 By +X, iit -z]{izio? ti} eee | a ae ae = ee ee a 4 t Dote : _—___ a [cae a en a I i feoliti{s-4j* —___— + “|Firsk_adigie % Sture code Coumeric) m= | Hedi charetdiers + PAN cumber Calptcie numeric) __—— Mo =| Nesta degre _* entity code (rumen eed nia Glpcibet — $$ a : 3 Ao.) ist 0-2) 19 (0-3) ot A 2403 aaa] 8 2[o-90-2} 1h 1 | 1 z 1 \ =x frst secre enory Code checkers Sede _“gesk:__peatt__eteee Charo a . 12 sd © | Daving license Validation > = - { MME itex€ Toso Digits (xx) Rot. pape oe 5 |- istrict code = Represent tne district in _eabich diving License sos issued ___ ee ce =. bce! 3-9 a 2)| Next + digts_- —__|+ Unique Vis Cense umber +>) Represent. Unique digits alho— |_ wed cored | to each rndividuct—_ sigh oc feesiy Pe ase tuo croracerss —— + Check _charccters = _Repreent eee ARE at ia aan z = = en Wen eo - * *[a-2)t23Co-s) 4a} fo-a) ist fof L Sa oe 1 : aod = a code R10 code Yt pra Srigue,eense si 2 S , | = rahe number = +. H_| Voter 1D vatidation + a z ee = = e — = - =| First Chovacter = a = ea Ee topitot Liectep ret SA) sy] peer (SA. ahs ‘= t co "3 ‘ L i = —{ Next 3 digrts = oath pes ates ™ peteies * Represent _pumenc fdentifier = ae Eee lost choracer = W837 f + Represent capita! letter ae ee os Vehicle registration ¢ i soo “= ~}-Mext _4_chesoster = Represent alphanumeric __ First_9 Characters. State code (Uppercase A-2) - Het doje = Distwict code (00-99) (Ost eter _+ Represent Uppemase letter. Dote : —_— ae 2) 423 (o-9]40 (s -20-s)f03 (A-2}G43 6 " Sa a Aiphanumeric aa fre = “cherracsers ti —| Customer ID Validation + {OL ~ Brarch code | *fa-2V iat lo-s} {a3 Lo-a} et $ J TESC code vovicicattom — 8 First _4_tettes = Bank code e Be a tecter SS chenaerer _= Aksoys Zero _Loast_6__tetter <__Bront oie - 3) re [a aCa-23 {ato la -20-9] jong?

You might also like