Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

javascript operator

Status
Not open for further replies.

scrsadmin

Technical User
May 3, 2004
62
US
I normall write in VBscript but i was given a javascript and asked to fix a problem with the output. As i am reading through the script i don't understand som of the syntax.
Can someone tell me what does these do? I understand that it is assgining something to the variables but i done't understand what it is doing with the / and \ and /^.

dnRE = /dn: \w, \w/i;

cnRE = /^cn: (.*), (.*)/;

givenRE = /^givenname: (.*)/;
snRE = /^sn: (.*)/;
mailRE = /^mail: (\S+)/;
//testRE = /@test\.state\.nc\.us/i;
testRE = /@test\.nc\.gov/i;

 
A regular expression pattern is enclosed between "/"s. Within a regular expression, the "\" is the "escape" code, meaning that the following character is to be interpreted as a special character. The "^" anchors the pattern to the start of the search string. The "i" following the closing "/" means "ignore case".

So the first RE: /dn: \w, \w/i seems to me to mean:
Find the characters, "dn:", followed by a space, followed by any alphanumeric, followed by a comma, followed by a space, followed by any alphanumeric, ignoring case.

_________________
Bob Rashkin
 
Okay so then what does this do
cnRE = /^cn: (.*), (.*)/;

givenRE = /^givenname: (.*)/;

If i understand this right the value cn: with a space is what is will be matched against. But then what is the
(.*), (.*)
do?
 
does the givenRE = /^givenname: (.*)/;
mean to match givename: space and any character except newline?
and then does cnRE = /^cn: (.*), (.*)/;
mean to match cn: space any character except newline comma space any character except newline?
 
does the givenRE = /^givenname: (.*)/;
mean to match givename: space and any character except newline?
Actually: "givenname: at the start, "space", and any number of any character except newline.

Likewise on your second question. That is, ".*" means "0 or more" of ".".

_________________
Bob Rashkin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top