regExp problem...

V

Vidéotron

Hi,

A bit new to "more complex" expression... So here the case I have:

bla bla bla{TPL,some texte or numbers}bla bla bla.

I figured out how to write the expression to extract the "{TPL,some texte or
numbers}", wich is what I want to get using "/\{TPL,[^\{\}]\}/" wich to my
understanding mean anything that start with "{TPL," and end with "}". That
seem to be working fine.

The thing is that I have variation on the same thing that I also need to
extract. For exemple:

bla bla bla{TPL,alpha 1{alpha 2}alpha 3}bla bla bla.

Also, there could be any combination of no alpha 1 and/or no alpha 3, have
others "{alpha x}" included... What I really want to do it's to extract what
ever start with "{TPL," untile it's corresponding ending "}".

I have tried using the "|" to list some possibilities, giving stuff like
this:

/\{TPL,\{[^\{\}]\}|[^\{\}]\}/

But somehow it doesn't quite understand what I am trying to do. On some
occasion, the "closing" } was not included in the returning search. I have
also tried to put the 2 expression between square bracket and adding the *
operator to get to have multiple occurence, but that work even less.

So I figured out that my understanding of regular expression isn't up to
this challenge and I was windering if anyone could, at the very least point
me in the right direction, either to docs that would help me understand
regular expression or help me resolve this issue.

TIA


Eric Therrien
 
N

ninja

Vidéotron said:
Hi,

A bit new to "more complex" expression... So here the case I have:

bla bla bla{TPL,some texte or numbers}bla bla bla.

I figured out how to write the expression to extract the "{TPL,some texteor
numbers}", wich is what I want to get using "/\{TPL,[^\{\}]\}/" wich to my
understanding mean anything that start with "{TPL," and end with "}". That
seem to be working fine.

The thing is that I have variation on the same thing that I also need to
extract. For exemple:

bla bla bla{TPL,alpha 1{alpha 2}alpha 3}bla bla bla.

Also, there could be any combination of no alpha 1 and/or no alpha 3, have
others "{alpha x}" included... What I really want to do it's to extract what
ever start with "{TPL," untile it's corresponding ending "}".

I have tried using the "|" to list some possibilities, giving stuff like
this:

/\{TPL,\{[^\{\}]\}|[^\{\}]\}/

But somehow it doesn't quite understand what I am trying to do. On some
occasion, the "closing" } was not included in the returning search. I have
also tried to put the 2 expression between square bracket and adding the *
operator to get to have multiple occurence, but that work even less.

So I figured out that my understanding of regular expression isn't up to
this challenge and I was windering if anyone could, at the very least point
me in the right direction, either to docs that would help me understand
regular expression or help me resolve this issue.

TIA


Eric Therrien

Hello,

If all you want is just to, as you said, "extract what ever start with
'{TPL,' until it's corresponding ending '}'", try this:
/\{TPL,(.*)?\}/.
 
E

Eric Therrien

Hi,

One thing I forgot to say is that there might be more then one {TPL,some
texte or numbers} in each string I am looking at and I want to be able to
extract each single "TPL" individualy from the string.


"ninja" <[email protected]> a écrit dans le message de (e-mail address removed)...

Vidéotron said:
Hi,

A bit new to "more complex" expression... So here the case I have:

bla bla bla{TPL,some texte or numbers}bla bla bla.

I figured out how to write the expression to extract the "{TPL,some texte
or
numbers}", wich is what I want to get using "/\{TPL,[^\{\}]\}/" wich to my
understanding mean anything that start with "{TPL," and end with "}". That
seem to be working fine.

The thing is that I have variation on the same thing that I also need to
extract. For exemple:

bla bla bla{TPL,alpha 1{alpha 2}alpha 3}bla bla bla.

Also, there could be any combination of no alpha 1 and/or no alpha 3, have
others "{alpha x}" included... What I really want to do it's to extract
what
ever start with "{TPL," untile it's corresponding ending "}".

I have tried using the "|" to list some possibilities, giving stuff like
this:

/\{TPL,\{[^\{\}]\}|[^\{\}]\}/

But somehow it doesn't quite understand what I am trying to do. On some
occasion, the "closing" } was not included in the returning search. I have
also tried to put the 2 expression between square bracket and adding the *
operator to get to have multiple occurence, but that work even less.

So I figured out that my understanding of regular expression isn't up to
this challenge and I was windering if anyone could, at the very least
point
me in the right direction, either to docs that would help me understand
regular expression or help me resolve this issue.

TIA


Eric Therrien

Hello,

If all you want is just to, as you said, "extract what ever start with
'{TPL,' until it's corresponding ending '}'", try this:
/\{TPL,(.*)?\}/.
 
G

Georgi Naumov

You can use something like this:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title></title>
<script type="text/javascript">
/*****************************************
This function asumes the string
as argument and returns array
with all strings between {TPL
and }.
*****************************************/
function extractTrl(aString)
{
var trlArray=aString.match(/{TPL,[^}]*}/gi);
/*****************************************
Just clear the {TPL, and }
simbols.
*****************************************/
for(i=0;i< trlArray.length;i++)

trlArray=trlArray.substring(5,trlArray.length-1);
return trlArray;
}
var strTest="bla bla bla{TPL,some texte or numbers}bla bla bla.
bla bla bla{TPL,some 1texte or numbers}bla bla bla.";
var myArr=extractTrl(strTest);
alert(myArr[1]);
</script>
</head>
<body>



</body>
</html>

Eric Therrien напиÑа:
Hi,

One thing I forgot to say is that there might be more then one {TPL,some
texte or numbers} in each string I am looking at and I want to be able to
extract each single "TPL" individualy from the string.


"ninja" <[email protected]> a écrit dans le message de (e-mail address removed)...

Vidéotron said:
Hi,

A bit new to "more complex" expression... So here the case I have:

bla bla bla{TPL,some texte or numbers}bla bla bla.

I figured out how to write the expression to extract the "{TPL,some texte
or
numbers}", wich is what I want to get using "/\{TPL,[^\{\}]\}/" wich tomy
understanding mean anything that start with "{TPL," and end with "}". That
seem to be working fine.

The thing is that I have variation on the same thing that I also need to
extract. For exemple:

bla bla bla{TPL,alpha 1{alpha 2}alpha 3}bla bla bla.

Also, there could be any combination of no alpha 1 and/or no alpha 3, have
others "{alpha x}" included... What I really want to do it's to extract
what
ever start with "{TPL," untile it's corresponding ending "}".

I have tried using the "|" to list some possibilities, giving stuff like
this:

/\{TPL,\{[^\{\}]\}|[^\{\}]\}/

But somehow it doesn't quite understand what I am trying to do. On some
occasion, the "closing" } was not included in the returning search. I have
also tried to put the 2 expression between square bracket and adding the *
operator to get to have multiple occurence, but that work even less.

So I figured out that my understanding of regular expression isn't up to
this challenge and I was windering if anyone could, at the very least
point
me in the right direction, either to docs that would help me understand
regular expression or help me resolve this issue.

TIA


Eric Therrien

Hello,

If all you want is just to, as you said, "extract what ever start with
'{TPL,' until it's corresponding ending '}'", try this:
/\{TPL,(.*)?\}/.
 
G

Georgi Naumov

I cannot save the addition cleaning of the {TPL, (into loop). :(
/*****************************************
This function asumes the string
as argument and returns array
with all strings between {TPL
and }.
*****************************************/
function extractTrl(aString)
{
var trlArray=aString.match(/{TPL,[^}]*(?=})/g);
/*****************************************
Just clear the {TPL, simbols.
*****************************************/
for(i=0;i< trlArray.length;i++)
trlArray=trlArray.substr(5);
return trlArray;
}
var strTest="bla bla bla{TPL,some texte or numbers}bla bla bla.
bla bla bla{TPL,some 1texte or numbers}bla bla bla.";
var myArr=extractTrl(strTest);
alert(myArr[0]);

Georgi Naumov напиÑа:
You can use something like this:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title></title>
<script type="text/javascript">
/*****************************************
This function asumes the string
as argument and returns array
with all strings between {TPL
and }.
*****************************************/
function extractTrl(aString)
{
var trlArray=aString.match(/{TPL,[^}]*}/gi);
/*****************************************
Just clear the {TPL, and }
simbols.
*****************************************/
for(i=0;i< trlArray.length;i++)

trlArray=trlArray.substring(5,trlArray.length-1);
return trlArray;
}
var strTest="bla bla bla{TPL,some texte or numbers}bla bla bla.
bla bla bla{TPL,some 1texte or numbers}bla bla bla.";
var myArr=extractTrl(strTest);
alert(myArr[1]);
</script>
</head>
<body>



</body>
</html>

Eric Therrien напиÑа:
Hi,

One thing I forgot to say is that there might be more then one {TPL,some
texte or numbers} in each string I am looking at and I want to be able to
extract each single "TPL" individualy from the string.


"ninja" <[email protected]> a écrit dans le message de (e-mail address removed)...

Vidéotron said:
Hi,

A bit new to "more complex" expression... So here the case I have:

bla bla bla{TPL,some texte or numbers}bla bla bla.

I figured out how to write the expression to extract the "{TPL,some texte
or
numbers}", wich is what I want to get using "/\{TPL,[^\{\}]\}/" wich to my
understanding mean anything that start with "{TPL," and end with "}".That
seem to be working fine.

The thing is that I have variation on the same thing that I also needto
extract. For exemple:

bla bla bla{TPL,alpha 1{alpha 2}alpha 3}bla bla bla.

Also, there could be any combination of no alpha 1 and/or no alpha 3,have
others "{alpha x}" included... What I really want to do it's to extract
what
ever start with "{TPL," untile it's corresponding ending "}".

I have tried using the "|" to list some possibilities, giving stuff like
this:

/\{TPL,\{[^\{\}]\}|[^\{\}]\}/

But somehow it doesn't quite understand what I am trying to do. On some
occasion, the "closing" } was not included in the returning search. Ihave
also tried to put the 2 expression between square bracket and adding the *
operator to get to have multiple occurence, but that work even less.

So I figured out that my understanding of regular expression isn't upto
this challenge and I was windering if anyone could, at the very least
point
me in the right direction, either to docs that would help me understand
regular expression or help me resolve this issue.

TIA


Eric Therrien

Hello,

If all you want is just to, as you said, "extract what ever start with
'{TPL,' until it's corresponding ending '}'", try this:
/\{TPL,(.*)?\}/.
 
M

marss

Eric Therrien напиÑав:
Hi,

One thing I forgot to say is that there might be more then one {TPL,some
texte or numbers} in each string I am looking at and I want to be able to
extract each single "TPL" individualy from the string.

Try this

<html>
<head>
<script>
var str = "bla bla bla{TPL,alpha 1{alpha 2}alpha 3}bla bla bla b la bla
bla{TPL,beta 1{beta 2}}bla bla bla";
var re = /\{TPL,(([^{]|([{](?!TPL)))*)\}/g
var res = re.exec(str);
while(re.lastIndex != 0)
{
alert(res[1]);
res = re.exec(str);
}
</script>
</html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top