G
Gopinath
Hi JavaScript Gurus,
I've a question on Regular Expressions using RegExp object. I just
want to know whether it is possible to do the search (see below) using
RegExp. Any pointers would be of immense help. Thanks.
My simple JavaScript code (inside a function):
=======================
var strList = "~@!~1#Apple~@!~2#Orange~@!~3#Mango~@!~4#Grapes~@!~";
var strSearchStr = "~@!~3#(.[^~@!~]*)";
var objRegExp = new RegExp(strSearchStr, "gi");
var arrRegExp = objRegExp.exec(strStateList);
if (arrRegExp != null) {
document.write("<br>" + RegExp.$1);
}
delete(objRegExp);
return (true);
=======================
When I supply 3, I want to get the corresponding value that is Mango.
With the regular expression, I get the result I'm aiming for.
BUT...
if the list was changed to this:
var strList = "~@!~1#Apple~@!~2#Orange~@!~3#@!Mango~@!~4#Grapes~@!~";
basically Mango has been changed to @!Mango. I've added two characters
@ and ! which are the row delimiters on the list string.
Then my regular expression search fails. The pattern I'm using [^~@!~]
searches and excludes individual characters ~, @ and !. But I want it
to exclude the grouping (~@!~).
I've tried the following reg exp. searches with no luck:
~@!~3#(.[^(~@!~)]*)
~@!~3#(.[^(~@!~){0,1}]*)
Any idea as what I'm doing wrong. I know this should be pretty simple
to implement.
Thanks,
Gopi
I've a question on Regular Expressions using RegExp object. I just
want to know whether it is possible to do the search (see below) using
RegExp. Any pointers would be of immense help. Thanks.
My simple JavaScript code (inside a function):
=======================
var strList = "~@!~1#Apple~@!~2#Orange~@!~3#Mango~@!~4#Grapes~@!~";
var strSearchStr = "~@!~3#(.[^~@!~]*)";
var objRegExp = new RegExp(strSearchStr, "gi");
var arrRegExp = objRegExp.exec(strStateList);
if (arrRegExp != null) {
document.write("<br>" + RegExp.$1);
}
delete(objRegExp);
return (true);
=======================
When I supply 3, I want to get the corresponding value that is Mango.
With the regular expression, I get the result I'm aiming for.
BUT...
if the list was changed to this:
var strList = "~@!~1#Apple~@!~2#Orange~@!~3#@!Mango~@!~4#Grapes~@!~";
basically Mango has been changed to @!Mango. I've added two characters
@ and ! which are the row delimiters on the list string.
Then my regular expression search fails. The pattern I'm using [^~@!~]
searches and excludes individual characters ~, @ and !. But I want it
to exclude the grouping (~@!~).
I've tried the following reg exp. searches with no luck:
~@!~3#(.[^(~@!~)]*)
~@!~3#(.[^(~@!~){0,1}]*)
Any idea as what I'm doing wrong. I know this should be pretty simple
to implement.
Thanks,
Gopi