Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Retreive infor from string with specific pattern - perl statement ?

Status
Not open for further replies.

janvdk

IS-IT--Management
Jan 15, 2005
8
BE
Hi,


I'd like to write a perl search statement (regular expression I suppose) to find something in a string of which next line is an example :

<A href="/product/3076">Table</A> (2004) <A href="/product/3076"><img src=/images/xml.png border=0></A>


I'd like to extract to a variable for the example above the following information : "Table (2004)"

More details :
- the number 3076 out of the example will always be different (in length also)
- the value Table will also be different always (also in length)
- all other things will have the same syntax over and over


Thanks in advance for all your ideas !!!

Jan
 
Code:
awk '
BEGIN{FS="<A href=\"/product/[0-9]+\">"}
{sub(/<.*>/,"",$2);print $2}
' infile >outfile
 
cntr,

Thanks for your fast response !

I was unfamiliar with awk but I looked some things up and I am now up to the point where I can understand your piece of code.

Now I still have the following question :
how do I use this within perl ? I have version 5.8.6 (ActiveState for Windows).

Thanks !

Jan
 
In Perl, it would be written something like:
[tt]
$text=~/<A href="\/product\/[0-9]+">(.+?)<\/A>(.+?)<A href="\/product\//;
$str=$1.$2;
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top