473,857 Members | 1,841 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

match(regexp) deciphering

Hello all, I'm new to javascript--not too new to a few other
programming languages--and I need your help deciphering the Regexp in
the following string. Regular expresions are hard enough in Python, and
since I am new to javascript they are even harder. Well here's the
string, thanks for any and all help I receive.
document.URL.ma tch(/^(.+?)(?:\?(?:( .*?)@)?(.+))?$/)

Feb 28 '06 #1
2 4756
brad wrote:
Hello all, I'm new to javascript--not too new to a few other
programming languages--and I need your help deciphering the Regexp in
the following string. Regular expresions are hard enough in Python, and
since I am new to javascript they are even harder. Well here's the
string, thanks for any and all help I receive.

document.URL.ma tch(/^(.+?)(?:\?(?:( .*?)@)?(.+))?$/)


Match
the beginning of input (`^')
followed by
one or more occurrences (`+') of any character except newline (`.'),
shortest match wins (`?')
followed by none or one occurrence (`?') of
the literal character `?' (`\?')
followed by zero or one occurrence (`?') of
zero or more occurrences (`*') of any character except newline (`.'),
shortest match wins (`?')
followed by
`@'
where the match of the subexpression is not captured (`(?:...)'),
where the match of the subexpression is not captured (`(?:...)'),
followed by
one or more occurrences of any character except newline
followed by
the end of input
in the value of `document.URL' and return a reference to an Array-like
object (one including numerically iterable properties) with each match
of a captured paranthesed subexpression being available as property of
that object with numerical name, starting with "0" as the property name
for the first captured match.

<URL:http://developer.mozil la.org/en/docs/Core_JavaScript _1.5_Reference: Global_Objects: RegExp>
<URL:http://developer.mozil la.org/en/docs/Core_JavaScript _1.5_Reference: Global_Objects: String:match>

(Once you have learned how to read and interpret Regular Expressions,
they are no mystery to you anymore, no matter the used flavour. See
also <URL:http://oreilly.com/catalog/regex/>; the sample chapters
sufficed for me to date.)

Note that non-capturing parantheses are not backwards compatible. It is
better not to use them here, and to use the backreference with greater
index instead.

The code does not make sense because it appears to check for some form of
URI-inline authentication while it also indicates it runs in a client-side,
HTML environment (`URL' is a property of HTMLDocument DOM host objects).
However, this code must not apply to a valid http(s) URI; usernames and
passwords are not allowed in them and user agents that support them there
anyway are broken. Meaning that this is a security leak there that will be
fixed soon or is already fixed in the next version. So this is an approach
that is not at all reliable.
PointedEars
Feb 28 '06 #2
Thomas 'PointedEars' Lahn wrote:
brad wrote:
Hello all, I'm new to javascript--not too new to a few other
programming languages--and I need your help deciphering the Regexp in
the following string. Regular expresions are hard enough in Python, and
since I am new to javascript they are even harder. Well here's the
string, thanks for any and all help I receive.

document.URL.ma tch(/^(.+?)(?:\?(?:( .*?)@)?(.+))?$/)


[...] and return a reference to an Array-like object (one including
numerically iterable properties) with each match of a captured paranthesed
subexpression being available as property of that object with numerical
name, starting with "0" as the property name for the first captured match.


Sorry, that is nonsense. Should have been

.... starting with "0" as the property name for the match of the whole
expression, "1" for the captured match of the first paranthesed
subexpression (here: /.+?/) and so on.
PointedEars
Feb 28 '06 #3

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

Similar topics

20
3565
by: RobG | last post by:
I'm messing with getPropertyValue (Mozilla et al) and currentStyle (IE) and have a general function (slightly modified from one originally posted by Steve van Dongen) for getting style properties: function GetCurrentStyle( el, prop ) { if ( window.getComputedStyle ) { // Mozilla et al return window.getComputedStyle(el, '').getPropertyValue(prop) ); } // IE5+ else if ( el.currentStyle ) {
0
1822
by: Chris Croughton | last post by:
I'm trying to use the EXSLT regexp package from http://www.exslt.org/regexp/functions/match/index.html (specifically the match function) with the libxml xltproc (which supports EXSLT), but whatever I do gets errors. The examples use namespace regExp, but the supplied files use regexp, I've got it so that it at least doesn't complain about namespaces but it then complains that it can't find the match function. My stylesheet is:
8
2036
by: Dmitry Korolyov | last post by:
ASP.NET app using c# and framework version 1.1.4322.573 on a IIS 6.0 web server. A single-line asp:textbox control and regexp validator attached to it. ^\d+$ expression does match an empty string (when you don't enter any values) - this is wrong d+ expression does not match, for example "g24" string - this is also wrong www.regexplib.com test validator works fine for both cases, i.e. it is reporting "not match" for the...
7
3456
by: Csaba Gabor | last post by:
I need to come up with a function function regExpPos (text, re, parenNum) { ... } that will return the position within text of RegExp.$parenNum if there is a match, and -1 otherwise. For example: var re = /some(thing|or other)?.*(n(est)(?:ed)?.*(parens) )/ var text = "There were some nesting parens in the test"; alert (regExpPos (text, re, 3));
8
1525
by: Paddy | last post by:
Proposal: Named RE variables ====================== The problem I have is that I am writing a 'good-enough' verilog tag extractor as a long regular expression (with the 'x' flag for readability), and find myself both 1) Repeating sections of the RE, and 2) Wanting to add '(?P<some_clarifier>...) ' around sections because I know what the section does but don't really want the group.
11
2944
by: HopfZ | last post by:
I coudn't understand some behavior of RegExp.test function. Example html code: ---------------- <html><head></head><body><script type="text/javascript"> var r = /^https?:\/\//g; document.write( ); </script></body></html> ---------------------
6
2280
by: runsun pan | last post by:
Hi I am wondering why I couldn't get what I want in the following 3 cases of re: (A) var p=/(+-?+):(+)/g p.exec("style='font-size:12'") -- // expected
10
1806
by: vertigo | last post by:
Hello I need to use some regular expressions for more than one line. And i would like to use some modificators like: /m or /s in perl. For example: re.sub("<script.*>.*</script>","",data) will not cut out all javascript code if it's spread on many lines. I could use something like /s from perl which treats . as all signs (including new line). How can i do that ?
13
5777
by: laredotornado | last post by:
Hi, Does anyone have code that detects if a field has been entered in PO Box format? I'm trying to prevent users from entering PO Boxes for shipping addresses. Thanks, - Dave
0
9923
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9768
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10808
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9549
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7104
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5774
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4592
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4191
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3215
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.