Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
8 views

Javascript Assignment 4

Unit 4 sppu entc javascript notes B.E

Uploaded by

Madhura Peshave
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Javascript Assignment 4

Unit 4 sppu entc javascript notes B.E

Uploaded by

Madhura Peshave
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

DATE:

ASSIGNMENT- 4
QWbat I Cxprcuian and
reqular exprtAtlon bow tto
them. creote
Reqular Expzcuion(ReqEx) an patltrn
patlern wed to
natch. chaxackeg combinatbhs ln stingTa
Javaseript and other programminglanguagu,
they to SCarch, ccit , o
maniplat
bascd specikc palerns.
A reqular cxprcasian can bc crated In buo

1 Laing a itoral notathioni This s ehdorcd bctucr:


slashee Clpaditrn )
let eq cx = Lhello;

2 uing the RcqExp conatucto This


ohnyou heed to builda patkrD dynamially
RagExpl'hedla ").
Ln both Crprier
ca4es.,gea eqular
Dhjct
PAGE NO,
DATE
ODz Explain vaio
expreasioht. String methoc fox reqular
Javascript
that Support providu severcl string medhods
rtqular Cxprtong
match O: Searchesa
against a tqula exprrssion shing for
and
a match.
turn
an
-amay of the matches
letstr str ="Ihe raln in
let reslt = Shrmatch (lainSpainl¡)i
:

replace O': Searches sting fox a spccihzd


value 0r a rtqular expresion and retuzns
a
atingwith the specificd vale ls)
replaced
let t = Hello oxld":
let eult = str rplace (/Wasld "Ublverse).
searcb O:Executes search for a_ matoh
Lbetwee a tgular exprelsion apd
specihed sting. It reurnt ihe ndr of the
first match.

let at= "The rain in Cpain ntaye mainly


the
let index = str searchClain):

split ()'i Splits shing nto


subitings ualng atqular copreduion
PAGE NO.
DATE:

let str = apple, banana chety


let ult = stt. aplit (L, \ )
test C)': Tuts for a matoh
Rctuns true' false
in a
string
Let reqex = /hello:
let At = regex. test/"hello Lworld:

ex ec O':Eecutes search for match in


and cturng of
C
stang
in for m.ahion. It retuzns.
amay
match
la found
let reqex =/hello/:
let zesult = cacx
tge. cxec ("hello world ")
short note captuning in JS
Tn
tqular expreason, captunng
lused to qroup part cf a pallern and captuz
the match for later wseBy
By default +

captuing, ohich mean, hey


n membn for later e

Non-cap tunnq qDup, art qz9ua that da


not captut he matchmlanin they do not
the matched are ueful
store
lohen youneed to qanup conlent They
eleroento but dopt
need to store the
Tn TavaSript,non- capturing
capturning gzup
crtatd uaih
PAGE N0.
DATE:

Example'
let reqex= /sbello) (worl d)/.
(wozld)
Jet sult s qex.exec (* hello wodo').
console.loq (ault C); //sazld"
hello matched but not captzcdi
0orld s botthmatched and captuzed
Au Explain wth erample CommOn chazacer
dasses.

Character clase n rtqular exprtaions


alow Ar mathing specihie types of charactr
Some characte dasiey Include:
Dot): Mathe a cingle characer ecpt
hawline charactra

Jet reqex =/at;


let eiult "cat "matchlragex):
2.dMatches any diqit lo-g.
let tege Ad t/
let eult " 2029match(gtx)
3 a : Matchs any abrd chaxckerfalphanumaie
underscos)
let
Jet ewt ="hello toordnatch (Tegex);
PAGE NO.

DATE:

\s': Matche any ohiteçpace characer Csçoc.


tabi, newhne)

let reudlt - "Hella klorld " matchlsego)


non-digit character
1D':Matche any
let
led eut abc match (rtgen)
\hw'Matches any non-wordcharacer
l
lete t .
Qs.match (rcge):
\Si Matches ahy non-whik spac charactr
let
let eiult a "Hello"match (tgtx);
TS code to perform mltihn
makching
To perfoxm mulilinemathing
you can m' flag Thic flag teae te
beqioing (A) and end lag
sof thashing a
the beqining and end of each ln
Example
PAGE NO.
DATE:

let str= Hello Alorld


Hello Ubiyerse
Hello Muttiverse

Jet tgex Hello fo:


let eut sshr. atch (rtqex)
Th theabove code, the ^Hello pattern
matches Hello at the start of eachJinthe
due to the m' flag The eaut ill be
6

ArstHello fom each hin

You might also like