How to get this string to give me the exact matching result
session[username_or_email]
the expression
<html>
<body>
<script type="text/javascript">
var str="session[username_or_email]";
var patt1=/ID|un|name|login_username|userid|username|user|Email|uname|usr|log|email|mail|nick|CUST|account|wpName1|textbox|pw|session[username_or_email]/i;
document.write(str.match(patt1));
</script>
</body>
</html>
the result now is username
Thankyou.
Just escape the
[with\[so it isn’t treated as a special regex control character, but just a normal character to search for.You can see it work here: http://jsfiddle.net/jfriend00/CuWKV/
You don’t actually have to escape the
]because it is only an expected regex control character when a[has come before it though it does not harm to escape it also.