473,737 Members | 6,642 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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|trig ger2)(.*)(trigg er3|trigger4)/si ;
but obviously i can't.. cause it doesn't work..
your ideas are very welcome!
thanks!!

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

ap******@hotmai l.com (Lydia Shawn) wrote in
news:12******** *************** ***@posting.goo gle.com:
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|trig ger2)(.*)(trigg er3|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|trigg er2)
\s*
([\d.]+)
\s*
(trigger3|trigg er4)/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/AwUBPzWfKWPeouI eTNHoEQJXXwCg9y Y/GXb8OXYXVVjlTtO L7QOA5/kAoJZU
LA2duAEVvyDkVmE ZcIX0tcHq
=nJA/
-----END PGP SIGNATURE-----
Jul 19 '05 #2
On 10 Aug 2003 02:56:10 -0700, Lydia Shawn <ap******@hotma il.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|trigg er2)\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
16980
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 extract 35 characters (including "T") from a file and then go to next line?
1
4674
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? Here is my code: <asp:DataList id=dlKommuner runat="server" Width="400px" RepeatColumns="2" CellPadding="3"> <AlternatingItemStyle Width="200px" CssClass="arow"> </AlternatingItemStyle>
9
2695
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 perform updates. All the styles that are set are being followed by all templated columns with the exception for the update column. The update column does set the BackColor appropriately but when setting its ForeColor the LinkButton's color is blue and...
4
2125
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
5689
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
9370
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: " Return-Path: X-Original-To: Received: from
3
5725
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 PIC (1). ID-PARTICIPANT PIC (6).
3
10586
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 database from text extracted from PDF documents. However, I am having a difficult time finding or developing the appropriate code to convert the PDF streams into text strings. Has anyone developed code to convert PDF's to Text? I was able write a...
1
3508
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 the ArrayList back from pgm3 how to extract and separate the fields out fo the ArrayLists? Question2: When pgm3 gets ArrayList back from pgm2 how to separate the
0
8968
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9334
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9258
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9207
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8207
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6749
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6052
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4569
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.