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

Matching multiple strings from a file

4
Hi, I am trying to match multiple strings per line from a file and extract them into an array. Apparently the first match is assigned $1, how do I know what the last match is ie $last?? I would like to set up a for loop to enter these values into an array: psuedo code below to extract all html tag per line in the file master, array is mastertags:

while (<$master>)
{
$_=~/(<.*?>)/g;
for (my $i=1; $i <= last value; $i++)
{
$mastertags [$x]=$i;
$x++;
}
}
Mar 19 '08 #1
1 1574
nithinpes
410 Expert 256MB
The value of $1 changes dynamically with each match found. In your case, though you are using /g option, you are not using a loop to parse through each match and end up getting only the first match in each line. You can try this:
Expand|Select|Wrap|Line Numbers
  1. my $m;
  2. while(<>) {
  3.   push @mastertags,$1 while(/(<.*?>)/g) ; ## push all the matches into array
  4.   $m=$1;      ## holds the string matched
  5. }
  6. print "last string matched:$m\n\n";  
  7. print "$_\n" foreach(@mastertags);
  8.  
Mar 19 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Xah Lee | last post by:
# -*- coding: utf-8 -*- # Python # Matching string patterns # # Sometimes you want to know if a string is of # particular pattern. Let's say in your website # you have converted all images...
1
by: Oat | last post by:
I am a little stomped and wandering if someone might have an idea how to go about doing this. following on from this guide http://www.4guysfromrolla.com/webtech/031004-1.shtml on matching a...
3
by: Day Of The Eagle | last post by:
Jeff_Relf wrote: > ...yet you don't even know what RegEx is. > I'm looking at the source code for mono's Regex implementation right now. You can download that source here ( use the class...
5
by: Jamie Jackson | last post by:
Two fairly basic questions: I need to supply a method with an array of strings, which will eventually be used to pattern match against another array of strings. 1. Is there a good way to span...
0
by: Tom Warren | last post by:
I found a c program called similcmp on the net and converted it to vba if anybody wants it. I'll post the technical research on it if there is any call for it. It looks like it could be a useful...
10
by: javuchi | last post by:
I'm searching for a library which makes aproximative string matching, for example, searching in a dictionary the word "motorcycle", but returns similar strings like "motorcicle". Is there such a...
5
by: olaufr | last post by:
Hi, I'd need to perform simple pattern matching within a string using a list of possible patterns. For example, I want to know if the substring starting at position n matches any of the string I...
7
by: Captain Dondo | last post by:
I'm working on a terminal emulator for an embedded system. The key requirements are small size, code clarity, maintainability, and portability. We have machines that regularly see a service life...
0
by: moconno5 | last post by:
Hello again, I am still working on my same project and have run into another little problem. I have created a flat file with data from a server, each line looks like this: BLAT Search Results ...
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: 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: 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: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.