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

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -