473,387 Members | 1,549 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,387 software developers and data experts.

Problem with RegExp: several occurrences

Sorry, I'm new to RegExp. I couldn't solve the problem myself. That's
why I dare to ask here for a little advice... ;-)

What I want to achieve: return all occurrences of L[x] were x is one
or more digits

I have the following code

var mtt = "abcde L[36]: fghij L[4]: klmn";
var fre = "(L\\[\\d+\\])";
var sugus = execRegExp(mtt,fre);

alert(sugus[1]);
alert(sugus[2]);

function execRegExp(myStr, myRegExpStr) {
var regex = new RegExp(myRegExpStr, "g");
var results = regex.exec(myStr);
return results;
}

I expect the code to return "L[36]" in sugus[1] and "L[4]" in
sugus[2], but sugus[2] is undefined. I set the flag g! In my opinion
it should return all occurrences ;-)

What's wrong with my RegExp. How can I make it also return "L[4]"?

thanks for any hint of my wrong doing... ;-)

Jul 25 '07 #1
1 1251
On Jul 25, 1:18 pm, test2000 <test2...@gmx.netwrote:
Sorry, I'm new to RegExp. I couldn't solve the problem myself. That's
why I dare to ask here for a little advice... ;-)

What I want to achieve: return all occurrences of L[x] were x is one
or more digits

I have the following code

var mtt = "abcde L[36]: fghij L[4]: klmn";
var fre = "(L\\[\\d+\\])";
var sugus = execRegExp(mtt,fre);

alert(sugus[1]);
alert(sugus[2]);

function execRegExp(myStr, myRegExpStr) {
var regex = new RegExp(myRegExpStr, "g");
var results = regex.exec(myStr);
return results;

}

I expect the code to return "L[36]" in sugus[1] and "L[4]" in
sugus[2], but sugus[2] is undefined. I set the flag g! In my opinion
it should return all occurrences ;-)

What's wrong with my RegExp. How can I make it also return "L[4]"?

thanks for any hint of my wrong doing... ;-)
It is simpler to do it like this:

var mtt = "abcde L[36]: fghij L[4]: klmn";
sugus = mtt.match(/L\[\d+\]/g);
alert(sugus[0]);
alert(sugus[1]);

Jul 25 '07 #2

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

Similar topics

1
by: python_charmer2000 | last post by:
I want to match several regexps against a large body of text. What I have so far is similar to this: re1 = <some regexp> re2 = <some regexp> re3 = <some regexp> big_re = re.compile(re1 +...
1
by: Tim Arnold | last post by:
Hi, I've got a list of 1000 common misspellings, and I'd like to check a set of text files for those misspellings. I'm trying to figure out the fastest way to do it; here's what I'm doing now...
2
by: Mr.Clean | last post by:
I am working on modifying a syntax highlighter written in javascript and it uses several regexes. I need to add a language to the avail highlighters and need the following regexes modified to...
2
by: brad | last post by:
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...
11
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;...
3
by: VUNETdotUS | last post by:
Hi, I am working with this regexp to extract address: city, state, and zip. This version kinda works but it extracts one element of an array instead of three and keeps my "city" too long, including...
8
by: The Frog | last post by:
Hi everyone, I am having some trouble with an SQL statement that I just cant seem to get to work. I have imported some data into MS Access from another application and have a single table with...
5
by: gentsquash | last post by:
In a setting where I can specify only a JS regular expression, but not the JS code that will use it, I seek a regexp component that matches a string of letters, ignoring case. E.g, for "cat" I'd...
3
by: Happy Face | last post by:
Hi, All, I encountered this strange problem while using function preg_match. The following is the php code. when I set the line: $text = str_repeat('*', 12500); preg_match will return 0 for...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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...
0
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,...
0
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...
0
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...

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.