J
John Kotuby
Hi all,
I am trying to learn how to use regular expression objects in JavaScript.
I am missing some very basic JavaScript concept.
While playing around with regular expressions from a 3rd party regex
creator, I tried pasting a regex expression that contained \\ into a
JavaScript function which, of course, interpreted the double backslash as a
comment indicator.
The JScript documentation states:
"Notice that because the backslash itself is used as the escape character,
you cannot directly type one in your script. If you want to write a
backslash, you must type two of them together (\\)."
Also I have seen that to declare a regular expression object it is not
correct to use apostrophes or double quotes to delimit the expression.
For example...
theRegExpObj=/(^\s*)|(\s*$)/g
rather than
theRegExpObj="/(^\s*)|(\s*$)/g"
So back to my original question. How does one use \\ in a JavaScript
function if it is meant as an escape code for the backslash rather than the
beginning of a comment?
Thanks for any answers.
I am trying to learn how to use regular expression objects in JavaScript.
I am missing some very basic JavaScript concept.
While playing around with regular expressions from a 3rd party regex
creator, I tried pasting a regex expression that contained \\ into a
JavaScript function which, of course, interpreted the double backslash as a
comment indicator.
The JScript documentation states:
"Notice that because the backslash itself is used as the escape character,
you cannot directly type one in your script. If you want to write a
backslash, you must type two of them together (\\)."
Also I have seen that to declare a regular expression object it is not
correct to use apostrophes or double quotes to delimit the expression.
For example...
theRegExpObj=/(^\s*)|(\s*$)/g
rather than
theRegExpObj="/(^\s*)|(\s*$)/g"
So back to my original question. How does one use \\ in a JavaScript
function if it is meant as an escape code for the backslash rather than the
beginning of a comment?
Thanks for any answers.