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

extract strings between alternating text

hi there,

i want to extract the numbers from this example

input:

bla trigger3 trigger4 trigger1 blabla trigger1 5000.00 trigger3
trigger1 trigger2 trigger2 600.00 trigger4
trigger1 50.00 trigger4

i want to extract the numbers everytime they occur between trigger1 or
2 and trigger3 or 4.

so output:
5000,00
600,00
50,00
i thought i could use something like this

$return =~ /($trigger1|trigger2)(.*)(trigger3|trigger4)/si ;
but obviously i can't.. cause it doesn't work..
your ideas are very welcome!
thanks!!

lydia
Jul 19 '05 #1
2 4361
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

ap******@hotmail.com (Lydia Shawn) wrote in
news:12**************************@posting.google.c om:
hi there,

i want to extract the numbers from this example

input:

bla trigger3 trigger4 trigger1 blabla trigger1 5000.00 trigger3
trigger1 trigger2 trigger2 600.00 trigger4
trigger1 50.00 trigger4

i want to extract the numbers everytime they occur between trigger1 or
2 and trigger3 or 4.

so output:
5000,00
600,00
50,00
i thought i could use something like this

$return =~ /($trigger1|trigger2)(.*)(trigger3|trigger4)/si ;
but obviously i can't.. cause it doesn't work..


Well, think about it. In words, that pattern matches:

The variable $trigger1 *or* the string "trigger2"
followed by as much text as possible
followed by the string "trigger3" or "trigger4".

So it would match pretty much the whole string, eh?

You want to match

The string "trigger1" or "trigger2"
followed by possible whitespace
followed by digits (and maybe a decimal point?)
followed by more possible whitespace
followed by the string "trigger3" or "trigger4"

right?
/(trigger1|trigger2)
\s*
([\d.]+)
\s*
(trigger3|trigger4)/six;

The most important thing when writing regular expressions is to state
*precisely* what you're looking for, and then translate it into small
chunks that correspond to what Perl's RE engine can do, and then write
the expression.

- --
Eric
$_ = reverse sort $ /. r , qw p ekca lre uJ reh
ts p , map $ _. $ " , qw e p h tona e and print

-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>

iQA/AwUBPzWfKWPeouIeTNHoEQJXXwCg9yY/GXb8OXYXVVjlTtOL7QOA5/kAoJZU
LA2duAEVvyDkVmEZcIX0tcHq
=nJA/
-----END PGP SIGNATURE-----
Jul 19 '05 #2
On 10 Aug 2003 02:56:10 -0700, Lydia Shawn <ap******@hotmail.com> wrote:
hi eric,
You want to match
The string "trigger1" or "trigger2"
followed by possible whitespace
followed by digits (and maybe a decimal point?)
followed by more possible whitespace
followed by the string "trigger3" or "trigger4"


exactly right! the variable was a mistake in my earlier posting but
you got it anyway!

for some reason though the | doesn't seem to do it's job..

=~ /(trigger1|trigger2)\s*([\d.]+)\s*(trigger3|trigger4)/six;

returns "trigger1"


Did you bother checking what was in $2?

It isn't magic you know, the documentation tells you what each
character in a regular expression does. You could try reading some
of it.

--
Sam Holden
Jul 19 '05 #3

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

Similar topics

9
by: Sharon | last post by:
hi, I want to extract a string from a file, if the file is like this: 1 This is the string 2 3 4 how could I extract the string, starting from the 10th position (i.e. "T") and...
1
by: Eirik Eldorsen | last post by:
I'm trying to set alternating bgcolor for a datalist with 2 columns. My problem is that its the alternating cell that get the bgcolor, not the row. Is it possible to set alternating color of rows?...
9
by: Max Weebler | last post by:
Hi, I have a datagrid built that has an alternating item style that sets the backcolor and ForeColor of its rows. I have 4 template columns. One of them has a LinkButton embedded in it to...
4
by: Barry | last post by:
How can I open a word doc and extract the text as text without any formatting characters?? -- Barry Fitzgerald
4
by: mike | last post by:
how can I change the font color for an alternating row where the column data is formatted as a link? setting a style in the stylesheet for a { color:white; }
9
by: flit | last post by:
Hello All, Using poplib in python I can extract only the headers using the .top, there is a way to extract only the message text without the headers? like remove the fields below: "...
3
by: maylee21 | last post by:
hi, anyone can help me figure out how to read data from a text file like this: 10980012907200228082002 and extract the data according to this kind of format: Record type 1 TY-RECORD ...
3
by: SteveB | last post by:
I have posted this question in the Visual Basic 2005 and Visual Basic .Net 2005 discussion groups, also. Hi. I am developing an application/web page with VB.Net that will populate a SQL...
1
by: =?Utf-8?B?SkI=?= | last post by:
Hello My pgm1 (User Interface Level) passes an empty ArrayList to pgm2 (Business Logic Level). pgm2 then calls pgm3 (Data Access Level) to populate the ArrayList. Question1: When pgm2 gets...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.