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

regExp problem...

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
Aug 8 '06 #1
5 1276

Vidotron wrote:
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,(.*)?\}/.

Aug 8 '06 #2
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" <ma****************@gmail.coma crit dans le message de news:
11**********************@p79g2000cwp.googlegroups. com...

Vidotron wrote:
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,(.*)?\}/.
Aug 8 '06 #3
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[i]=trlArray[i].substring(5,trlArray[i].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" <ma****************@gmail.coma écrit dans le message de news:
11**********************@p79g2000cwp.googlegroups. com...

Vidéotron wrote:
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,(.*)?\}/.
Aug 8 '06 #4
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[i]=trlArray[i].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[i]=trlArray[i].substring(5,trlArray[i].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" <ma****************@gmail.coma écrit dans le message de news:
11**********************@p79g2000cwp.googlegroups. com...

Vidéotron wrote:
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,(.*)?\}/.
Aug 8 '06 #5

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>

Aug 9 '06 #6

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

Similar topics

19
by: Magnus Lie Hetland | last post by:
I'm working on a project (Atox) where I need to match quite a few regular expressions (several hundred) in reasonably large text files. I've found that this can easily get rather slow. (There are...
0
by: Ed Leafe | last post by:
I recently upgraded to 4.1 alpha (MySQL 4.1.0-alpha-standard-log) on my Linux server, and came across a problem with a query that had been working in 3.23 that no longer worked in 4.1a. I've...
10
by: Andrew DeFaria | last post by:
I was reading my O'Reilly JavaScript The Definitive Guide when I came across RegExp and thought I could tighten up my JavaScript code that checks for a valid email address. Why does the following...
6
by: Mark Findlay | last post by:
I am trying to figure out how to set up my reg exp search so that the search will only match on the exact word. Here is the current problem code: Word1 = "RealPlayer.exe" Word2 = "Player.exe"...
1
by: geos | last post by:
hello, I have the problem writing the regular expression to verify the valid system path in the way that RegExp.$1 has to contain path up to the parent folder of a file, and RegExp.$2 should...
6
by: Christoph | last post by:
I'm trying to set up client side validation for a textarea form element to ensure that the data entered does not exceed 200 characters. I'm using the following code but it doesn't seem to be...
7
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...
9
by: vbfoobar | last post by:
Hello I am looking for python code that takes as input a list of strings (most similar, but not necessarily, and rather short: say not longer than 50 chars) and that computes and outputs the...
2
by: Uldis Bojars | last post by:
Hi All, I have encountered problems with JS RegExp.exec() and can't find what is the problem. Could you help me? formRequest is a function that extracts some information from XMLHTTPRequest...
4
by: r | last post by:
Hello, It seems delimiters can cause trouble sometimes. Look at this : <script type="text/javascript"> function isDigit(s) { var DECIMAL = '\\.'; var exp = '/(^?0(' + DECIMAL
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...

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.