473,772 Members | 2,478 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Different regular expression splitting in Firefox/IE

In Firefox, as in most regular expression engines, the split function
works like this:
"His name is <name>. His email address is <email>.".split (/<(.*?)>/) returns ["His name is ", "name", ". His email address is ", "email",
"."]

so that the text pattern in the parentheses is included in the result.

In Internet Explorer, however, the result is different:
"His name is <name>. His email address is <email>.".split (/<(.*?)>/)

returns ["His name is ", ". His email address is ", "."]

I would like to know if there is a way to get IE to include the text in
parentheses.
Thanks a lot,
Eric

Apr 18 '06 #1
7 2097
I found a rather lame workaround:
"His name is <name>. His email address is <email>.".repla ce(/<(.*?)>/g, "[#SPLIT#]$1[#SPLIT#]").split('[#SPLIT#]')

If you can come up with anything better, please share it.

Eric

Apr 18 '06 #2
Eric McGraw said on 18/04/2006 2:43 PM AEST:
In Firefox, as in most regular expression engines, the split function
works like this:

"His name is <name>. His email address is <email>.".split (/<(.*?)>/)


returns ["His name is ", "name", ". His email address is ", "email",
"."]

so that the text pattern in the parentheses is included in the result.

In Internet Explorer, however, the result is different:

"His name is <name>. His email address is <email>.".split (/<(.*?)>/)


returns ["His name is ", ". His email address is ", "."]

I would like to know if there is a way to get IE to include the text in
parentheses.

.split(/[<>]/);
--
Rob
Group FAQ: <URL:http://www.jibbering.c om/FAQ>
Apr 18 '06 #3
Thanks, but i would actually like to be able to filter what characters
can be in the brackets. Sorry for an incomplete example.

Eric

Apr 18 '06 #4
"Eric McGraw" <th************ @gmail.com> writes:
I found a rather lame workaround:
"His name is <name>. His email address is <email>.".repla ce(/<(.*?)>/g, "[#SPLIT#]$1[#SPLIT#]").split('[#SPLIT#]')

If you can come up with anything better, please share it.


It's a know defect in IE, where it doesn't follow the ECMAScript standard.

I don't think it's necessarily *that* lame a solution :)

But let's see if replace can't be used for something funny:

function mySplit(string, regexp) {
var offset = 0;
var collection = [];
string.replace( regexp, function(m,g,i, s) {
collection.push (string.substri ng(offset, i), g);
offset = i + m.length;
});
collection.push (string.substri ng(offset));
return collection;
}

And then
mySplit("His name is <name>. His email address is <email>.", /<(.*?)>/g)
returns ["His name is ", "name", ". His email address is ", "email", "."]
as it should (remember the "g" after the regexp literal if you want to
match more than once).

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Apr 18 '06 #5
Very helpful, thanks so much!

Eric

Apr 18 '06 #6
Lasse Reichstein Nielsen wrote:
"Eric McGraw" <th************ @gmail.com> writes:
I found a rather lame workaround:
"His name is <name>. His email address is
<email>.".repla ce(/<(.*?)>/g, "[#SPLIT#]$1[#SPLIT#]").split('[#SPLIT#]')

If you can come up with anything better, please share it.


It's a know defect in IE, where it doesn't follow the ECMAScript standard.


One can rightfully argue that an implementation that does not follow the
ECMAScript specification to the letter is not displaying a defect but is
a conforming implementation of ECMAScript, as different behavior and
language extensions are specified by ECMAScript to be conforming. Besides,
it is not IE that is the issue here, but Microsoft JScript.
PointedEars
Apr 19 '06 #7
Thomas 'PointedEars' Lahn <Po*********@we b.de> writes:
One can rightfully argue that an implementation that does not follow the
ECMAScript specification to the letter is not displaying a defect but is
a conforming implementation of ECMAScript, as different behavior and
language extensions are specified by ECMAScript to be conforming.
The allowances for conforming implementations in ECMAScript standard
3rd Ed. section 2 (Conformance) allows additional features, but does
not allow different semantics of standard features. It must satisfy:

| A conforming implementation of ECMAScript must provide and support
| all the types, values, objects, properties, functions, and program
| syntax and semantics described in this specification.

JScript in IE does not implement the semantics of the "split" method
on String.prototyp e, and as such is not a conforming implementation.

It's close enough to being conforming that it's usually safe to assume
conformance, and then memorize the exceptions (this is one, array
literal elisions is another that I can remember).
Besides, it is not IE that is the issue here, but Microsoft JScript.


If might be an issue in other uses of JScript too. I am not familiar
with these. It is an issue with the JScript implementation used by IE
by default, which is why I allow myself to call it a problem in IE.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Apr 19 '06 #8

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

Similar topics

1
1521
by: jnc | last post by:
I was wondering whether anyone could help me out splitting out the following string (an excel formula) using a regular expression. What I would like to be able to do is get the dependency paths, the sheets names and the rows and columns split into seperate variables. "=Sheet1!R1C1+Sheet1!R1C2"
18
3042
by: Q. John Chen | last post by:
I have Vidation Controls First One: Simple exluce certain special characters: say no a or b or c in the string: * Second One: I required date be entered in "MM/DD/YYYY" format: //+4 How ??
5
1101
by: Kerry | last post by:
Please help. I need a regular expression that parses a stream of up to 450 characters into 15 separate strings of up to 30 characters each. The regex must break at newlines. Ideally, the regex will "word wrap" that is, not break in the middle of words. I have the following: (?m:(?:(.)?){1,30}\s\n?){1,15}? This works well as long as the user leaves at least one whitespace character
7
25791
by: Anat | last post by:
Hi, What regex do I need to split a string, using javascript's split method, into words-array? Splitting accroding to whitespaces only is not enough, I need to split according to whitespace, comma, hyphen, etc... Is there a regex that does the trick? Thanks, Anat.
9
5706
by: lev | last post by:
Attempting to use javascript's regular expression methods to match a particular lab number and building which would then be copied to a pair of textfields, I found that general matching characters needing a backslash were not recoginized. The following adapted code that finds a two-button radio selection shows my problem: function labstat(){ for (i=1; i<3; i++){ if(document.tester.rm_mod.checked){ var lb = ...
4
1735
by: vishal | last post by:
Hello All: I am trying to work out a regular expression in a PyQt environment for time in hh:mm:ss format. Any suggestions? Thanks, Vishal
20
3424
by: Geoff Hill | last post by:
What's the way to go about learning Python's regular expressions? I feel like such an idiot - being so strong in a programming language but knowing nothing about RE.
5
5372
by: Just Another Victim of the Ambient Morality | last post by:
This won't compile for me: regex = re.compile('(.*\\).*') I get the error: sre_constants.error: unbalanced parenthesis
14
4991
by: Andy B | last post by:
I need to create a regular expression that will match a 5 digit number, a space and then anything up to but not including the next closing html tag. Here is an example: <startTag>55555 any text</aClosingTag> I need a Regex that will get all of the text between the html tags above (the html tags are random and i do not know them before hand). The match string always starts with at least 5 digits.
0
9621
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
9454
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,...
0
10106
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10039
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
9914
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8937
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...
1
7461
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5484
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3610
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.