Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / February 2008

Tip: Looking for answers? Try searching our database.

Dumb JavaScript question - how to use \\ not as a comment?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
John Kotuby - 11 Feb 2008 02:45 GMT
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.
Scott M. - 11 Feb 2008 02:55 GMT
Double forward-slashes (//) are comments in JavaScript.  Double back-slashes
(\\) are an escape code for a single back-slash.

-Scott

> Hi all,
>
[quoted text clipped - 25 lines]
>
> Thanks for any answers.
John Kotuby - 11 Feb 2008 03:04 GMT
Right Scott...

Dumb question it was indeed ;-)

Actually the problem I ran into did involve // found in a regular expression
that was generated by a regular expression builder.

Perhaps the expression generated was a mistake by the 3rd party program, but
I know I tried to paste it into a JavaScript function and it wouldn't work.

I will take more time to study regex and see if there is any case where I
would actually come across the occasion to use // in a regular expression. I
suspect there might be, possibly when doing a search match on a forward
slash.

I hope everyone got a good laugh over my mistake. I know I did.

> Double forward-slashes (//) are comments in JavaScript.  Double
> back-slashes (\\) are an escape code for a single back-slash.
[quoted text clipped - 30 lines]
>>
>> Thanks for any answers.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.