473,573 Members | 2,749 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 4385
-----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
16961
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
4667
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...
9
2684
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...
4
2114
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
5676
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
9258
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
5702
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
10575
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...
1
3502
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...
0
7746
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...
0
7986
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7736
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...
0
8036
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...
0
5258
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...
0
3701
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...
0
3699
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2167
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
999
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.