Regular Expressions 101

Community Patterns

Find specific document cookie value

0

Regular Expression
ECMAScript (JavaScript)

/
(?:(?:^|.*;\s*)test2\s*\=\s*([^;]*).*$)|^.*$
/

Description

Finds the value of a specific cookie. Use it in in this format:

alert(document.cookie.replace((?:(?:^|.*;\s*)test2\s*\=\s*([^;]*).*$)|^.*$))

The above code will find the value of the cookie called test2 and display it in a alert dialog.

Submitted by anonymous - 5 years ago