Regular Expressions

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

Quantifiers what do these do? + |

+ Quantifier — Matches between one or more digits/\d+/ | is 2nd alternative OR /\a|b/ find a or b

what do these do? /w /W [^ABC] [^A-Z]

/w (any word character) Matches any letter, digit or underscore. Equivalent to [a-zA-Z0-9_] /W (any non-word character) Matches anything other than a letter, digit or underscore [^except this] Matches any char except for an A, B or C [^A-Z]Matches any char except those in the range A-Z

What is a Regular Expression? https://www.regex101.com/

Regular expressions are used to perform pattern-matching and "search-and-replace" functions on text.

var str = "The rain in SPAIN stays mainly in the plain"; var res = str.match(/ain/g); //ain,ain,ain

The match() method searches a string for a match against a regular expression, and returns the matches, as an Array object.

escaping characters

\' single quote. \" double quote. \ backslash. \n new line. \r carriage return. \t tab. \b backspace. \f form feed.

General Tokens \r, \n, \t, \f, \s, \d,

\r (the carriage return), /\r/ \n (newline), \t (tab), \f (the form feed), \s (white space) \d (Matches any decimal digit. Equivalent to [0-9].) \0 (Null Character

^.+\s matches to the last white space

^ asserts position at start of the string .+ matches any character (except for \n) line terminator + Quantifier — Matches between one and unlimited times, as many times as possible, giving back as needed \s matches any whitespace character (equal to [\r\n\t\f\v ])

Flags Modifiers g, i /software/gi what does this mean

g(global)Tells the engine not to stop after the first match found. Continue until no more matches can be found. i(case insensitive)A case insensitive match is performed, meaning capital letters will be matched by non-capital letters and vice versa. //Looking for software throughout entire independent of case sensitivity

........................................$1...... $2 capture Groups / ( [ ] ) ( [ ] ) /g , '$1...$2' str.replace(/ ([a-z]) ([A-Z]) /g, "$1...$2"); // "This...Is...Spinal...Tap"

group 1 = any lowercase a-z group 2 =any uppercase A-Z Whenever lowercase is next to uppercase, input the value contained between $1 $2 No quotes needed between $capture groups

var vowels =/[aeiouy]/; if ( !str[0].match(vowels) ){...}

searches for a,e,i,o,u,y


Kaugnay na mga set ng pag-aaral

Chap 13 Sec 5 Authentication Protocol Facts x7

View Set

Chapter 7: Bacterial and Viral Systems

View Set

Marketing: Supply Chain Chapter 6

View Set

- Module 13 Volume of Cylinders, Cones, Spheres, Prisms, and Pyramids- Surface Area of Rectangular Prisms, Cylinders, and Spheres

View Set

Combo with 37 review questions for activity and exercise and 1 other

View Set