473,382 Members | 1,717 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Does anybody undesrstand this line of code from prototype.js

Hello, this sentence is from the Ajax.Request.prototype function in
prototype.js:

this.url += (this.url.match(/\?/) ? '&' : '?') + parameters;

I understand what it does but I don't know how does "/\?/" work. Would
it be the same as "this.url.match('?')" ?

- What is each slash for?
- Is "\?" an escape character?

Can anybody help me?

Carlos from Barcelona.

Apr 19 '06 #1
2 1432
eq******@gmail.com wrote:
Hello, this sentence is from the Ajax.Request.prototype function in
prototype.js:

this.url += (this.url.match(/\?/) ? '&' : '?') + parameters;

I understand what it does but I don't know how does "/\?/" work. Would
it be the same as "this.url.match('?')" ?

- What is each slash for?
- Is "\?" an escape character?

Can anybody help me?

Carlos from Barcelona.


Hi Carlos

Its a regular expression, broken down

/ is the start of the expression

\? match a question mark anywhere in the url

/ is the end of the expresssion.

the \ is an escape character because ? on its own means something
else entirely.

Regular expressions are a very powerful tool for matching patterns
in strings. There is plenty of info on the web about them and
one here.

http://www.sitepoint.com/article/exp...s-javascript/2

HTH

Chris

Apr 19 '06 #2
eq******@gmail.com said the following on 4/19/2006 7:16 AM:
Hello, this sentence is from the Ajax.Request.prototype function in
prototype.js:
It's a line of code, not a sentence. But another reason why I don't use
prototype.js
this.url += (this.url.match(/\?/) ? '&' : '?') + parameters;

I understand what it does but I don't know how does "/\?/" work. Would
it be the same as "this.url.match('?')" ?
Close. It uses the ternary operator to see if it has a ? in the url and
then appends parameters accordingly.
- What is each slash for?
It is part of the Regular Expression that match is using.
- Is "\?" an escape character?


Yes.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Apr 19 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: vakap | last post by:
function show() { var s = '' ; for (var i = 0; i<arguments.length; s += '\n'+arguments) ; typeof(window) != 'undefined' ? window.alert(s) : WScript.Echo(s) ; } function f(){}...
6
by: deejaybags | last post by:
could someone please have a look at this and tell me why it segfaults. i am confused as all hell! stringman.h void load_string(char *newString); char * remove_string(); char *...
14
by: Anoop | last post by:
Hi, I am new to this newsgroup and need help in the following questions. 1. I am workin' on a GUI application. Does C# provides Layout Managers the way Java does to design GUI? I know that it...
89
by: Cuthbert | last post by:
After compiling the source code with gcc v.4.1.1, I got a warning message: "/tmp/ccixzSIL.o: In function 'main';ex.c: (.text+0x9a): warning: the 'gets' function is dangerous and should not be...
9
by: pamelafluente | last post by:
Hi, I was "studying" the famous (public code) BusyBox. I see the instruction: var busyBox = new BusyBox as in var busyBox = new BusyBox("BusyBox1", "busyBox", 4, "gears_ani_", ".gif",...
14
by: webEater | last post by:
I have a problem, it's not browser specific, and I don't get a solution. I have an (X)HTML document, I show you a part of it: .... <!--<div class="pad">--> <div id="eventImages"><img src=""...
92
by: Heinrich Pumpernickel | last post by:
what does this warning mean ? #include <stdio.h> int main() { long l = 100; printf("l is %li\n", l * 10L);
3
by: kj | last post by:
OK, here's another construct I've run into in the jQuery source that I can't figure out. It looks like this: return new jQuery.prototype.init( selector, context ); So basically, as far as I...
19
by: Prisoner at War | last post by:
Okay, Folks, I guess my real burning concern all along is a "high-level" one: just how does JavaScript interact with CSS? Right now, my newbie self only knows JavaScript and CSS to *co-...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.