regex - RegExp (^|\\?|&) in javascript -


could please me understand javascript regexp :

cbreg = new regexp('((^|\\?|&)' + cbkey + ')=([^&]+)') // cbkey string 

i confused (^|\\?|&) portion. mean?

thanks !

well first of given regex created string literal double backslashes become single backslash in resulting regex (because that's how escaping works in string literal):

(^|\?|&) 

the | means or, have:

^    - start of line, or \?   - question mark, or &    - ampersand 

a question mark on own has special meaning within regex, escaped question mark matches actual question mark.

the parentheses means matches 1 of choices before matching next part of regex. without parens third choice include next part of expression (whatever in cbkey).


Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

javascript - Preserving URL fragment through CAS sign-on -

asp.net mvc - Implementing normal user/pass, Twitter & Facebook auth -