RegExp

2004-10-14 Thread Mandar Rahurkar
Hi, 
   I have a bunch of text (multiple paragraphs). I want to find a sentence 
like 'Susan * the water' (No its not a HW problem). Here's what I am 
doing:

#! /usr/bin/perl


use warnings;

$file="temp.txt";
open(fp,$file) or die "Cant open $file :$!\n";


local $/="";
while () {
   while( /(susan)(\D+)[the|water]\b/xig )
{
  print "$1 $2\n"
}
}

this catches sentences like:

susan swam in the water for long time whereas i wud like
susan swam in the water

What am i doing wrong ?

Mandar


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




RegExp

2001-06-29 Thread Timothy

I'm sure this is a really easy question but here goes. I'd like to replace
each leading blank of a string with   I have currently:

$strLine =~ s/^\s+/ /g;

I can see that this will simply take all leading blanks and replace them
with one   but how do I get *each* leading blank to be replaced with
a  ? TIA:) 
-- 
---
[EMAIL PROTECTED]

Which is worse: ignorance or apathy?  Who knows?  Who cares? 
---



RegExp

2001-06-30 Thread Morgan

Hi

Can someone help me out with a simple question?

I need to match some parts if a document. and store it in variables so
I can send the matching string into more than one new file.

RegExp



while (<>) {
$pub =~ if (//i .. /<\/pub>/i )   # or is it better with an
array or hash?
}
open (DOC, ">$newfile" or die$!;
print DOC $pub;
close (DOC) or die $!;

open (FILE, ">$new" or die $!;
print FILE $pub;
close (FILE);
--

I can't get it to work.
Am I on the trail or have I just lost it :)








regexp

2003-06-11 Thread Jaschar Otto
Hi,
i've got a problem with regexp,
i have a multiline string like

this is
a multi
line string



and i want to do a regexp that replaces
everything that is NOT "a","b","c"  or "d"
with \s, except \n of course.
i got something like

$string =~ s/![abcd]//g;

but that doesn't work, maybe because
it recognizes ! not as negation but as
character...
so how to do it ?

thanks
  Jaschar Otto


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Regexp

2002-08-26 Thread David Samuelsson (PAC)

more regexps..

$_ comes in this form: 

servername:D:\CC_Storage\Views\EUSDNKG_Madeleine_Tae68_view.vws [uuid 
74a6b3b0.d1cd11d4.896e.00:b0:d0:83:b4:9b]

i want $_ to be just the uuid number that is: 74a6b3b0.d1cd11d4.896e.00:b0:d0:83:b4:9b

how do i get that the easiest way? all $_ are the same they are all within brackets 
[text here variables, exept . and :]

//Dave



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Regexp

2002-09-18 Thread Panel Vincent - A53

I have a problem with a regular expression :

I process a text file with a list of names.

I would like to reformat names like

  Francois de   la Varenne
Macha Meril 
BuzzMac Cormack

(there must be at least two words in the name)
to something like this :

[EMAIL PROTECTED]
[EMAIL PROTECTED]
[EMAIL PROTECTED]

In other words : "[EMAIL PROTECTED]".

I tried the following thing and it doesn't work ($name already contains one
of those names) :

$name=~s/\s*(\w+)\s+(\w+)(\s+(\w+))*\s*/$1.$2$3\@domain.top/


Does anyone knows the right regexp to do this (I guess it's the second
expression with $s which is wrong)

Vincent Panel.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




regexp

2004-05-19 Thread Graf Laszlo
Hi
I have the following HTML structure:


BBB


CCC


Every line in this structure is an element of an array,
named @lines, and I access the elements using a foreach loop.
When I know the tag's name, by example 'sm:a',
and I need to extract the information contained by ''
and '' pair and the tags too, how should I proceed ?
I tried a regexp like this:
foreach $s (@lines) {
   print "$s";
   if($s =~ m|^(\\n)(.*?)(\\n<\/sm:a>)$|s){
  ($l,$c,$r) = ($1,$2,$3);
  print "OK\n";
  print "l: '$l'\n";
  print "c: '$c'\n";
  print "r: '$r'\n";
   }else{
  print "HEHE\n";
   }
}
Help me. Thank you.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Regexp

2004-05-28 Thread max4o
I have the following lines:

g00:~> perl -e '
$a = "aa** a";
$b = $a;
$b =~ qw/$b/;
print "Yes\n" if $a =~ /^$b/;
print $b'
Nested quantifiers in regex; marked by <-- HERE in m/^aa** <-- HERE  a/ at
-e line 5.

Is there a way to make the regexp takes '$b' as string, because
I see the non characters are problem.

Thanks

-
This mail is from: <[EMAIL PROTECTED]>
-

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Regexp

2004-06-19 Thread Mandar Rahurkar
Hi All,
   what wud be the regexp for :

1. substituting last s of every word 
   e.g., forests become forest,  goats becomes goat

2. removing all one and two lettered words 
   e.g., a,an

Thanks,
Mandar


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




regexp

2003-08-26 Thread Anton Arhipov
Hi,

i've a string like "BLAH" (guotes included).
i need to control if the BLAH is in uppercase and then if it is in 
uppercase truncate the quotes ("), so "BLAH" becomes BLAH.

any solutions?

Thx



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Regexp

2002-05-09 Thread Eduardo Cancino

Hello!

I have a lot of trouble understanding regexes, i just don't get how to parse
a file with:

"Hablar es el arte de sofocar e interrumpir el pensamiento". Thomas Carlyle
(1795-1881); historiador y ensayista escocés.
"Se aprende más por lo que la gente habla entre sí o por lo que se
sobrentiende, que planteándose preguntas". Rudyard Kipling (1865-1936);
escritor inglés, de origen indio.
"Hay palabras que suben como el humo, y otras que caen como la lluvia".
Marquesa de Sévigné,(1626-1696); escritora francesa.
"El destino es el que baraja las cartas, pero nosotros somos los que
jugamos". William Shakespeare (1564-1616); poeta y dramaturgo inglés.

I need to separate for print the quote, then the name and the coments.

Could someone give me some pointers??

Thanks!


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




regexp

2001-11-13 Thread birgit kellner

I have a file structured like this:

1. This is a heading
...
1.1. A subheading
1.2. Another subheading
2. Another heading
..
3. Yet another heading
.

I want to extract (a) each heading number with the matching heading text, 
and (b) the immediately following text up to, and not including, the first 
subheading.

I got the first part, but not the second:
my $counter = 1;
my %headinghash;
open (FILE, ") {
my $file = $_;
chomp($file);
if ($file =~ /^($counter)\.\s(.*?)$/) {
$headinghash{$counter} = $2;
#missing code here, need data up to next occurrence of "$counter.1"
$counter++;
}
}
close (FILE);

I need the regexp to take off at that point where there was a match for the 
heading, and then extract everything from there up to the occurrence of 
"$counter.1". Would this necessarily involve slurping the whole file into 
an array first?


Thanks in advance for any advice,

Birgit Kellner



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Regexp

2008-08-21 Thread Jim
Hi all,

Given a wordlist @WordList and a file $content, how do I construct a
regexp to search for every word in @WordList in $content.

I have tried the following, which does not work:

foreach $i (@WordList)
{
print "Searching: " . $i . "\n\n";
if($content =~ m/$i/)
  {
print "Found Word " . $i . "\n";
  }
}

@WordList might contain up to 1000 or 2000 words, and changes daily,
so I don't think regexp::list is the answer.

Thank you for your time.

Jim


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




regexp

2007-05-10 Thread oryann9
I have this block of text:

Node:  dudbqa02 Message group: MoM_OpC_ADM-m-s
Application:   OGTP Object:syslog Severity:   
  Critical Text:  WebSph

ere Broker v6003[2998366]:
(QWMB01.EG500)[8225]BIP2951I: Event generated by user
code. Additional information :
'msgagt=ESM_WMB_AIX,sec_id=Sec

_id,severity=Low,msgnode=qwmbap01.cardinalhealth.net,utc={2007-04-26
18:01:59.472+00:00},om={UID=3a7affd6-f420-11db-80b1-,AlertCod

e=AEM001,AlertType=AEM-default,AppName=AEM-CommonService2,Message=5004:An
error has been reported by the BIPXML4C
component.:XML}' 'MS_Alert_E

SM_Integrator.InsertToSYSLOG' '{2}' '{3}' '{4}' '{5}'
'{6}' '{7}' '{8}' '{9}' :
QWMB01.1aef50ec-1001--0080-dae5df22a0ad:
/build/S600_P/src

/DataFlowEngine/ImbRdl/ImbRdlThrowExceptionStatements.cpp:
158: SqlThrowExceptionStatement::execute:
ComIbmComputeNode: MS_Alert_ESM_Integrato

r#FCMComposite_1_2,cma={Location=Not_found,BusUnit=Not_found}

 

The strings I need out of this are:

msgagt=ESM_WMB_AIX

sec_id=Sec_id

severity=Low

msgnode=qwmbap01.cardinalhealth.net

utc={2007-04-26 18:01:59.472+00:00}

om={

UID=3a7affd6-f420-11db-80b1-

AlertCode=AEM001

AlertType=AEM-default

AppName=AEM-CommonService2

Message=5004:An error has been reported by the
BIPXML4C component.:XML

}


I have this test code but does not work:

#!/usr/bin/perl

use strict;
use warnings;
use diagnostics;

my $ovo= qq(/home/dbsmith/out);
my $msgagt = qr/(\w+\=\w+)/is;
open (my $out, "+<", $ovo) or die "file '$ovo' was not
opened $!";

while (<$out>) {
s/^\s+|\s+$//g; ## rid of newlines at
begin and end
next unless length $_;  ## skip line of length
undef
print $_ if (/$msgagt/);
}


Any help/ideas?
thank you.

__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




regexp

2007-01-31 Thread oryann9
In this regexp
   
  my $regexp  = qr/(\d+\x3a1108
  |\w+\x3a1108{1,} ) /;
   
  vs.
   
  my $regexp1  = qr/(\d+\x3a1108
  |\w+\x3a1108){1,} /;
   
  does the {1,} construct outside the parens () mean the entire string 1 or 
more times and within the parens mean only the last string \x3s1180 1 or more 
times?
   
  What is the diff?
   
  thank you. 

 
-
Don't pick lemons.
See all the new 2007 cars at Yahoo! Autos.

Regexp

2007-04-25 Thread Somu

why wont the following work?

$q = shift;
$p = "pass";
if ( $q =~ m/$p/i ) { print 'match' }

But it works on changing the $q and $p places..

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




REGEXP

2005-04-26 Thread DBSMITH
Please help me find the regexp to replace -o-b- - - -f
thank you!

s/sg//, s/\- {1,}(\w{1,})//,print +(split)[5,6,7], if (m/f01(\d+)/gi )


my $_ has these lines in it:

-o-b- - - -f
F01045

-o-b- - - -f
F01046

-o-b- - - -f
F01047

-o-b- - - -f
F01048

-o-b- - -f
F01049

-o-b- - - -f
F01050

-o-b- - - -f
F01051


Derek B. Smith
OhioHealth IT
UNIX / TSM / EDM Teams
614-566-4145


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




RegExp

2014-03-08 Thread rakesh sharma
Hi all,
how do you get all words starting with letter 'r' in a string.
thanks,rakesh
  

regexp validation (arbitrary code execution) (regexp injection)

2011-06-01 Thread Stanisław Findeisen
Suppose you have a collection of books, and want to provide your users
with the ability to search the book title, author or content using
regular expressions.

But you don't want to let them execute any code.

How would you validate/compile/evaluate the user provided regex so as to
provide maximum flexibility and prevent code execution?

-- 
Eisenbits - proven software solutions: http://www.eisenbits.com/
OpenPGP: E3D9 C030 88F5 D254 434C  6683 17DD 22A0 8A3B 5CC0

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Regexp problem

2004-09-01 Thread Hamish Whittal
Hi all,

(Example 1)
I have the following lines:
This is some text..MBAAAEgAAAQAB
blaah,blaah
=+=+=+=+=+=+=+=+=+=+=+

(Example 2)
but sometimes it looks like this:
This is some text..
MBAAAEgAAAQAoBAAAQKAREDSCETRTBDFS
blaah,blaah
=+=+=+=+=+=+=+=+=+=+=+

Now, given this, I am wanting to skip over the text when I find it
(bounded by  and =+=+=+)

So, I have a loop as follows:
LINE: while ( <> ) {
next LINE if (m/\.{4}/s .. /(\+\=\+)$/);
print;
}

The "next" works fine if the  tag is not split as in example
(2) above, but fails when the  tag is split as in example (1)
above.

Can anyone show me what I am doing wrong.

Thanks
H
-- 
 -o)
  /\\Message void if penguin violated
 _\_VDon't mess with the penguin

Hamish Whittal  South Africa
082 803 5533021 671 7710


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: RegExp

2004-10-14 Thread JupiterHost.Net

Mandar Rahurkar wrote:
Hi, 
Hello,
   I have a bunch of text (multiple paragraphs). I want to find a sentence 
like 'Susan * the water' (No its not a HW problem). Here's what I am 
doing:

#! /usr/bin/perl

use strict;
use warnings;
$file="temp.txt";
my $file = 'temp.txt';
open(fp,$file) or die "Cant open $file :$!\n";
open(FP,$file) or die "Can not open $file : $!\n";
local $/="";
why ??
while () {
while() {
   while( /(susan)(\D+)[the|water]\b/xig )
{
  print "$1 $2\n"
}
}
this catches sentences like:
susan swam in the water for long time whereas i wud like
susan swam in the water
What am i doing wrong ?
(\D+) matches more than you expect. What do you mean in "Susan * the 
water" with the *?

A word with no digits?
Try /(susan)\s+([a-zA-Z]+)\s+the water/
Mayeb if your a bit more descriptive of what you are trying to get
HTH :)
Lee.M - JupiterHost.Net
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: RegExp

2004-10-15 Thread Jenda Krynicky
From: "JupiterHost.Net" <[EMAIL PROTECTED]>
> Mandar Rahurkar wrote:
> >I have a bunch of text (multiple paragraphs). I want to find a
> >sentence 
> > like 'Susan * the water' (No its not a HW problem). Here's what I am
> > doing:
> > 
> > #! /usr/bin/perl
> 
> use strict;
> 
> > use warnings;
> > 
> > $file="temp.txt";
> 
> my $file = 'temp.txt';
> 
> > open(fp,$file) or die "Cant open $file :$!\n";
> 
> open(FP,$file) or die "Can not open $file : $!\n";
> 
> > local $/="";
> 
> why ??

Because otherwise the  would read individual lines. And the 
sentence can easily be split to several lines.
If you set $/ to "" then the file is read in paragraphs, not lines. 
That is each  now returns several lines until it finds an empty 
one.
 
> > while () {
> 
> while() {
> 
> >while( /(susan)(\D+)[the|water]\b/xig )

\D means "non-digit", What's wrong with sentence 
Susan filled 3 glasses with the water?
And the \D+ matches as much text as it can, it won't stop on the 
first "the water".

[the|water] means exactly the same as for example [aehrtw|]. Not what 
you meant right? I believe you want something like this:

while (/(susan[^.?!]+the\s+water\b)/ig) {
print $1,"\n";
}

Jenda
= [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: RegExp

2004-10-15 Thread JupiterHost.Net
local $/="";
why ??

Because otherwise the  would read individual lines. And the 
sentence can easily be split to several lines.
If you set $/ to "" then the file is read in paragraphs, not lines. 
That is each  now returns several lines until it finds an empty 
one.
You rock Jenda! I always learn something new from you. Thanks
Lee.M - JupiterHost.Net
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: RegExp

2004-10-15 Thread Mandar Rahurkar
Thanks Guys this is good however what does character class inside the 
square brackets mean..
I think I need to get mastering regular expressions book..

Mandar

> 
>   while (/(susan[^.?!]+the\s+water\b)/ig) {
>   print $1,"\n";
>   }
> 
> Jenda
> = [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =
> When it comes to wine, women and song, wizards are allowed 
> to get drunk and croon as much as they like.
>   -- Terry Pratchett in Sourcery
> 
> 
> 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: RegExp

2004-10-15 Thread Steve Bertrand
> Thanks Guys this is good however what does character class inside the
> square brackets mean..
> I think I need to get mastering regular expressions book..

Read: # perldoc perlretut
and:  # perldoc perlre

which will help give you an understanding of regex's. This is only my
opinion of course, and I still have a long way to go with this, but
character classes are well defined and described within.

Note that all Perl books seem great (as far as my reading) so let me
know if you actually buy/read the book and how it is.

(I just bought Perl -- Objects, References and Modules, and it's great
so far (O'Reilly of course)).

Just my .02

Steve
>
> Mandar
>
>>
>>  while (/(susan[^.?!]+the\s+water\b)/ig) {
>>  print $1,"\n";
>>  }
>>
>> Jenda
>> = [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =
>> When it comes to wine, women and song, wizards are allowed
>> to get drunk and croon as much as they like.
>>  -- Terry Pratchett in Sourcery
>>
>>
>>
>
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>  
>
>
>



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




RegExp equivalencies

2005-01-24 Thread Michael Kraus
G'day...

Is:

my ($id) = $item =~ /_(\d+)$/;

Equivalent to:

$item =~ /_(\d+)$/;
$id = $1;

Thanks heaps...

-Mike




Wild Technology Pty Ltd , ABN 98 091 470 692
Sales - Ground Floor, 265/8 Lachlan Street, Waterloo NSW 2017
Admin - Level 4 Tiara, 306/9 Crystal Street, Waterloo NSW 2017
Telephone 1300-13-9453 |  Facsimile 1300-88-9453
http://www.wildtechnology.net
DISCLAIMER & CONFIDENTIALITY NOTICE:  The information contained in this email 
message and any attachments may be confidential information and may also be the 
subject of client legal - legal professional privilege. If you are not the 
intended recipient, any use, interference with, disclosure or copying of this 
material is unauthorised and prohibited.   This email and any attachments are 
also subject to copyright.  No part of them may be reproduced, adapted or 
transmitted without the written permission of the copyright owner.  If you have 
received this email in error, please immediately advise the sender by return 
email and delete the message from your system.



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




regexp trouble

2001-05-07 Thread Johan Groth

Hi,
I want to strip a variable of all characters including a token, i.e.
aaa_bbb_ccc_ddd would become bbb_ccc_ddd.  As you can see I want to get rid of
aaa_. Does anyone know how to acomplish this in Perl?

I've tried:
$tmp = "aaa_bbb_ccc_ddd"
$tmp =~ /^\w+_/
$tmp = $';

but that results in $tmp eq "ddd" instead of "bbb_ccc_ddd".

/Johan

--
Johan Groth (xghjn) ! Tel. mobil: 0703 - 24 25 27
Cell Network!   Kontoret:  054 - 14 25 27
[EMAIL PROTECTED] ! Bofors: 0586 - 820 14
[EMAIL PROTECTED]




Regexp Question

2001-05-10 Thread Gross, Stephan

I want to match the following:
1) the letters "PT"
2) a space or nothing
3) a word that may or may not be in parentheses or even not exist
and return item #3 (which may be null)
Example:
PT (XYZ) or PT XYZ or PTXYZ or PT
should return "XYZ" except the last case, which should return "".
 
I can do everything except the parentheses case.  Any ideas?
 
Thanks!
___
Stephan Gross   Loral Skynet 908-470-2388 [EMAIL PROTECTED]
 

 



Interesting? regexp

2001-05-24 Thread Aaron Craig


Here's a reg exp problem that's got me up at night.  I'm looking for 
currency and numbers in various formats.  The currency symbol and the 
actual character code of the number I'm looking for may vary, depending on 
the file I'm looking at, as we're working in Unicode and looking at 
languages from all over the world.  I'm also using utf8.

Basically valid formats would be:
$123
$ 123
123$
123 $

and up to here, I'm okay:

my $sText = "Foo $ 123 bar 123$ hello $123 world 123 $";
my $reNumber   = "\x{0030}-\x{0039}"; # these may be different depending on 
the language, but let's work with English
my $reCurrency = "\\x{0024}|\\x{00a3}"; # just to keep it simple
my @asCurrencies = $sText =~ 
/[$reNumber]?\x{0020}?[$reCurrency]\x{0020}?[$reNumber]?/g;
foreach my $currency (@asCurrencies)
 {
 print "$currency\n";
 }

ok.

I want to add in the text for currency symbols, like "dollar" and "pound", 
so that I match on either a currency symbol or a currency word and grab the 
numbers to the left of to the right.

Here are the strings for those already formatted for utf8:

my $string = 
"(\x{0064}\x{006f}\x{006c}\x{006c}\x{0061}\x{0072}\x{0073})|(\x{0070}\x{006f}\x{0075}\x{006e}\x{0064}\x{0073})";
 
# (dollar)|(pound)

I've tried all sorts of variations on parentheses etc. in the reg exp, to 
no avail.  I've checked the docs on forward and backward checking, and 
messed around with it some, but either that's not what I need, or I haven't 
completely grasped the concept yet.

Any ideas?


Aaron Craig
Programming
iSoftitler.com




regexp Help

2001-05-30 Thread Kyrytow, Stefan

If someone could please help me.

I can't figure out how to use a variable in a regexp.

Example.
I am writing a script to parse a web log and report on all the hosts in the
log.
However I have a command line option to exclude a domain from the report.
My problem is that I can't figure out how to use the inputed value in a
regexp.

Log Format
host.domain.com

I want to be able to exclude domain.com

I have tried:
while( $exclude_domain !~ /$host/ ) { ... }

Any help is appreciated.

STEFAN KYRYTOW
EDS CANADA
Leveraged Platform Solution Centre
t 416.814.4911
p 416.517.2252
[EMAIL PROTECTED]




regexp question

2001-06-07 Thread Martin Weinless

Hello,

This is probably not a true beginners question - it refers to an example
that I use in class when we discuss regexps.

Here is the problem:

take the regexp '.n+..?.?v*.'

By all that is sacred, if we use the string 'supernova', there should be
no match since there are too many characters before the 'n'

However, any regexp checking code will report a match.

Any ideas/comments/etc.

Thanks

Marty W.

WINDOWS: 32 bit extensions and a graphical shell for a 16 bit patch to an
8 bit operating system originally coded for a 4 bit microprocessor,
written by a 2 bit company that can't stand 1 bit of competition.





Regexp question

2001-06-25 Thread Tim Wood

Hi

I'm new to perl and have a question about regexps that hopefully one of you 
can help with.

I'm trying to parse out links from web pages, so essentially I have a string 
of the form:



So what I want to do is find an expression to match against that.

Secondly, if there is an easy way to put the contents of href="" into a 
variable, that would be most useful too!

I think the expression should look something like (assume string in $str):

   if ($str =~ m/\/  ) { ...} 

but then I'm unsure about where the matched text would end up - in $2?

Any help greatly appreciated

Cheers
Tim



Re: RegExp

2001-06-29 Thread Jeff 'japhy' Pinyan

On Jun 29, Timothy said:

>I'm sure this is a really easy question but here goes. I'd like to replace
>each leading blank of a string with   I have currently:
>
>   $strLine =~ s/^\s+/ /g;

That /g is pointless there...

>I can see that this will simply take all leading blanks and replace them
>with one   but how do I get *each* leading blank to be replaced with
>a  ? TIA:) 

You could take the Randal Schwartz approach:

  $strLine =~ s/\G\s/ /g;

or you could take the backreference approach:

  $strLine =~ s/^(\s+)/' ' x length($1)/e;

That first one replaces a space with ' ', as long as it was found
right after the last one.  The second one replaces all leading spaces with
' ' repeated as many times as necessary.

-- 
Jeff "japhy" Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
I am Marillion, the wielder of Ringril, known as Hesinaur, the Winter-Sun.
Are you a Monk?  http://www.perlmonks.com/ http://forums.perlguru.com/
Perl Programmer at RiskMetrics Group, Inc. http://www.riskmetrics.com/
Acacia Fraternity, Rensselaer Chapter. Brother #734
**  Manning Publications, Co, is publishing my Perl Regex book  **




Re: RegExp

2001-06-30 Thread Abdulaziz Ghuloum

Hello,
Where did you come up with 
$pub =~ if (//i .. /<\/pub>/i ) 
I guess you want to get the sting between the   tags, but that's not
how it's done.
You can do 
push @pub, m#(.*?)#g; #it's better with an array
but that would break if you have the  and  on separate lines. 
Basically, you cannot parse an XML file with one regexp.  Take a look at the
XML::Parser module or friends.

Hope this helps.


On Sat, 30 Jun 2001 13:05:15 +0200, Morgan said:
> Hi
>  
>  Can someone help me out with a simple question?
>  I need to match some parts if a document. and store it in variables so
>  I can send the matching string into more than one new file.
>  RegExp
>  
>  while (<>) {
>  $pub =~ if (//i .. /<\/pub>/i )   # or is it better with an
>  array or hash?
>  }
>  open (DOC, ">$newfile" or die$!;
>  print DOC $pub;
>  close (DOC) or die $!;
>  
>  open (FILE, ">$new" or die $!;
>  print FILE $pub;
>  close (FILE);
>  --
>  
>  I can't get it to work.
>  Am I on the trail or have I just lost it :)






Re: RegExp

2001-06-30 Thread Jeff 'japhy' Pinyan

On Jun 30, Morgan said:

>I need to match some parts if a document. and store it in variables so
>I can send the matching string into more than one new file.

>while (<>) {
>$pub =~ if (//i .. /<\/pub>/i )
>}

I think what you want to do here is:

  while (<>) {
print if m!!i .. m!!i;
  }

(Print to the proper filehandle, of course.)  This means "print the line
if it is in between a line holding  and a line holding .

-- 
Jeff "japhy" Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
I am Marillion, the wielder of Ringril, known as Hesinaur, the Winter-Sun.
Are you a Monk?  http://www.perlmonks.com/ http://forums.perlguru.com/
Perl Programmer at RiskMetrics Group, Inc. http://www.riskmetrics.com/
Acacia Fraternity, Rensselaer Chapter. Brother #734
**  Manning Publications, Co, is publishing my Perl Regex book  **




simple regexp

2001-07-04 Thread Matija Papec


This is pretty beginners question, how can I extract IP number from $s?

$s = "ALL: 172.184.70.165 # PORT: 59"
Pattern have to match four numbers separated by "."


Besides I have some array and need to insert some values into it(somewhere
in the middle). "perldoc -f splice" says that it only does replacement and
truncation. Do you guys have some idea how to make this work? tnx!



-- 
Matija



RegExp problem

2001-07-09 Thread saliminl

Hi.  This is my first post.  I'm trying to write a script that retrieves data 
from a text file.  The text files have several hundred instances of the string 
"EAMBER (non-constraint) = #" where the # is a number that can be negative and 
the last spacing after the equals sign is variable.  My problem is in the 
loop; my expression matches ok, but it skips every other instance of the 
expression (leaving me with half my data).  I added the counting variable as a 
debug to see what was going on, and in files with 600 instances of the string, 
it ends up at 300.  Thanks a lot.

-
#!/usr/bin/perl

print "Input file name: \n";
chomp($in_file = );

open (INFILE, "$in_file") or die ("Cannot open file");
open (EAMBEROUT, ">sum.EAMBER") or die("Cannot open file");

$EAMBER_count = 0;
while () {
 if ($EAMBER =  =~ /EAMBER\s\(non-constraint\)\s=\s+(.\d+.\d+)/c) {
  $EAMBERARRAY[$EAMBER_count] = $1;
  print EAMBEROUT "$EAMBER_count $EAMBERARRAY[$EAMBER_count]\n";
  $EAMBER_count++;
 }
}

close (INFILE);
close (EAMBEROUT);


Neema Salimi
[EMAIL PROTECTED]




regexp issues

2001-07-23 Thread Stephanie Stiavetti

I need to make sure that a field contains ONLY letters... and this is the
regular expression I'm using:

$name=~/^[a-zA-Z]+/


it doesn't seem to be working in the test script that I wrote:

#!/usr/bin/perl -w

print "what's your name?";
$name=;
chomp $name;

$flag=$name=~/^[a-zA-Z]+/;
if (!$flag)  {

print "sorry... try again.\n";
}

else {

print   "woo hoo!\n";

}


what am I doing wrong?  also, will said regular expression accept foreign
characters as letters, like an umlaut?  (ö)





`°º¤,ô¿ô,¤º°``°º¤,ô¿ô,¤º°``°º¤,ô¿ô,¤º°``°º

Stephanie J. Stiavetti
Production Tools
Industrial Light + Magic
415-448-3213 <-|-> [EMAIL PROTECTED]

`°º¤,ô¿ô,¤º°``°º¤,ô¿ô,¤º°``°º¤,ô¿ô,¤º°``°º

And then the day came when the risk to 
stay tight in a bud became more painful 
than the risk it took to blossom.  
   --Anais Nin

`°º¤,ô¿ô,¤º°``°º¤,ô¿ô,¤º°``°º¤,ô¿ô,¤º°``°º

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




regexp example

2003-06-10 Thread Oleg

 Hi,

 Could anybody help me with the following task:

Need to write a script that will convert "\text_or_digits [digits] " (begins
with the backslash and
there is one space before "[")  in the text into "text_or_digits[digits]"
(no backslash and no space).
For Example:

Word1 word2 any othe(34)r 444word \xxxwww [44] f  \www22233 [1] Text
\d[111] \rr \ [233]

=> (need to be converted into)

Word1 word2 any othe(34)r 444word xxxwww[44] f  www22233[1] Text
\d[111] \rr [233]


Thanks in advance!

Oleg





-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: regexp

2003-06-11 Thread Janek Schleicher
Jaschar Otto wrote at Wed, 11 Jun 2003 11:53:11 +0200:

> i've got a problem with regexp,
> i have a multiline string like
> 
> this is
> a multi
> line string
> 
> 
> 
> and i want to do a regexp that replaces
> everything that is NOT "a","b","c"  or "d"
> with \s, except \n of course.

\s is not one character, it stands usually for a whole character class!
Do you mean an empty string ("") or just a blank (" ") instead?

> i got something like
> 
> $string =~ s/![abcd]//g;

character class negation works with [^...],
in your case it would be
$string =~ s/[^abcd]//g;

> but that doesn't work, maybe because
> it recognizes ! not as negation but as
> character...
> so how to do it ?

Please read also
perldoc perlre
for details.


Greetings,
Janek

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: regexp

2003-06-11 Thread Jaschar Otto
Hi
>\s is not one character, it stands usually for a whole character class!
>Do you mean an empty string ("") or just a blank (" ") instead?

i ment a blank (" ").

>character class negation works with [^...],
>in your case it would be
>$string =~ s/[^abcd]//g;

Thanks a lot, that worked perfect,
maybe i was too blind but i couldn't
find this character calss negation
in perlre when i searched last time
before your post :-)

anyways, thanks again



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: regexp

2003-06-11 Thread James Edward Gray II
On Wednesday, June 11, 2003, at 05:14  AM, Jaschar Otto wrote:

$string =~ s/[^abcd]//g;
Thanks a lot, that worked perfect,
Transliterate is probably a better choice for this kind of thing.  It's 
certainly more efficient.  You would use it like this:

$string =~ tr/abcd/ /c;

James

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


RE: regexp

2003-06-11 Thread Dan Muey
> On Wednesday, June 11, 2003, at 05:14  AM, Jaschar Otto wrote:
> 
> >> $string =~ s/[^abcd]//g;
> >
> > Thanks a lot, that worked perfect,
> 
> Transliterate is probably a better choice for this kind of 
> thing.  It's 
> certainly more efficient.  You would use it like this:

Just curious, how is it more efficient?
Can you use anchors in tr ?
because in the =~ example above it would match a string:
abcd foo monkey
But not 
monkey abcd foo
While the tr version would match both.

Just wondering

Dan

> 
> $string =~ tr/abcd/ /c;
> 
> James
> 
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: regexp

2003-06-11 Thread James Edward Gray II
On Wednesday, June 11, 2003, at 09:21  AM, Dan Muey wrote:

On Wednesday, June 11, 2003, at 05:14  AM, Jaschar Otto wrote:

$string =~ s/[^abcd]//g;
Thanks a lot, that worked perfect,
Transliterate is probably a better choice for this kind of
thing.  It's
certainly more efficient.  You would use it like this:
Just curious, how is it more efficient?
Transliterate is faster because it doesn't have to fire up the Regular 
Expression engine.

Can you use anchors in tr ?
No, but there were no anchors used in the above search.  The problem 
was to replace all non qw(a b c d) characters with a space.  That's a 
textbook perfect definition of what Transliterate does.

because in the =~ example above it would match a string:
abcd foo monkey
But not
monkey abcd foo
While the tr version would match both.
Na, you're confusing your ^ characters.  ;)  What you said is written:

s/^abcd/ /;

The search above was:

s/[^abcd]/ /;

It means any non qw(a b c d) character.

James

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: regexp

2003-06-11 Thread Rob Dixon
Dan Muey wrote:
> > On Wednesday, June 11, 2003, at 05:14  AM, Jaschar Otto wrote:
> >
> > > > $string =~ s/[^abcd]//g;
> > >
> > > Thanks a lot, that worked perfect,
> >
> > Transliterate is probably a better choice for this kind of
> > thing.  It's
> > certainly more efficient.  You would use it like this:
>
> Just curious, how is it more efficient?

Because it doesn't involve any pattern matching. The translation
is a straightforward byte for byte mapping.

> Can you use anchors in tr ?

You can't use regexes at all with tr//.

> because in the =~ example above it would match a string:
> abcd foo monkey

The caret at the start of a character class negates the
sense of the class, so /[abcd]/ matches a character which is
any one of the four letters 'a', 'b', 'c' or 'd'. /[^abcd]/
will match any single character except these four. In the
expression

  ($string = 'abcd foo monkey') =~ s/[^abcd]/ /g;

the regex matches four times - once for each of the first
four characters.

> But not monkey abcd foo

  ($string = 'monkey abcd foo') =~ s/[^abcd]/ /g;

also matches four times - starting at offset 7 within
the string.

> While the tr version would match both.

Both have the same effect as

  $string =~ tr/a-d/ /;

HTH,

Rob




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: regexp

2003-06-11 Thread Dan Muey
> The caret at the start of a character class negates the
> sense of the class, so /[abcd]/ matches a character which is 
> any one of the four letters 'a', 'b', 'c' or 'd'. /[^abcd]/ 
> will match any single character except these four. In the expression

Ooo yeah the brackets change the carrot. What a monkey I am.
Thanks Rob for the clarification once again. 
Dan

> 
>   ($string = 'abcd foo monkey') =~ s/[^abcd]/ /g;
> 
> the regex matches four times - once for each of the first
> four characters.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



cisco regexp

2002-07-30 Thread Hernan Marcelo Salvarezza

Hello all, i am parsing a cisco log and i can'nt find the exact
regexp,following goes the log and the script..

Jul 25 10:39:12 10.0.0.1 852: 1d23h: %VOIPAAA-5-VOIP_CALL_HISTORY:
CallLegType 2, ConnectionId 0 0 0 0, SetupTime *10:46:49.143 GMT Thu Jul
25 2002, PeerAddress 0051122323223, PeerSubAddress , DisconnectCause 0
, DisconnectText , ConnectTime *10:47:09.753 GMT Thu Jul 25 2002,
DisconnectTime *10:47:09.753 GMT Thu Jul 25 2002, CallOrigin 1,
ChargedUnits 0, InfoType 2, TransmitPackets 0, TransmitBytes 0,
ReceivePackets 358, ReceiveBytes 7064
...

my $dtgT = '\d|:|\.';   
my $peer = 'PeerAddress';
my $upT = 'ConnectTime';
my $downT = 'DisconnectTime';
my $prefT = '"0051"';

my $find = qr/$peer\s* ([$prefT](\d+)) .*  \s*$upT\s* ([\*$dtgT]+) .*
\s*$downT\s* ([\*$dtgT]+) .*  /xo;

This works fine and gives me the following output:
0051122323223,16:11:29.482,16:11:29.482

Now i need to get the first part of the log(Jul 25 10:39:12) with the
regexp and print it before the number string
(0051122323223,16:11:29.482,16:11:29.482),so i use the following  regexp
to do that

my $find = qr/(.*?) (\d+\.\d+\.\d+\.\d+.\d+.\d+)\s*   /xo
it works fine and brings this output:

Jul 23 11:01:45 
Jul 23 11:14:44 
Jul 23 11:14:45  

but it does'nt work when i put the two regexps together

my $find = qr/(.*?) (\d+\.\d+\.\d+\.\d+.\d+.\d+)\s* $peer\s*
([$prefT](\d+)) .*  \s*$upT\s* ([\*$dtgT]+) .* \s*$downT\s* ([\*$dtgT]+)
..*  /xo;

Sorry for the long mail,any ideas?,thanks in advance
Hernan


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Regexp

2002-08-26 Thread David . Wagner

Something along the line of:

my $uuid ;

if ( ! /\[uuid\s+([^\]]+)/ ) {
 # if no hit then do something
   # warn or die depending on what you expect
   }
  $uuid = $1;
 
  If you want $_ then you can do $_ = $uuid;

Wags ;)

-Original Message-
From: David Samuelsson (PAC) [mailto:[EMAIL PROTECTED]]
Sent: Monday, August 26, 2002 05:12
To: '[EMAIL PROTECTED]'
Subject: Regexp 


more regexps..

$_ comes in this form: 

servername:D:\CC_Storage\Views\EUSDNKG_Madeleine_Tae68_view.vws [uuid
74a6b3b0.d1cd11d4.896e.00:b0:d0:83:b4:9b]

i want $_ to be just the uuid number that is:
74a6b3b0.d1cd11d4.896e.00:b0:d0:83:b4:9b

how do i get that the easiest way? all $_ are the same they are all within
brackets [text here variables, exept . and :]

//Dave



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Regexp

2002-08-26 Thread Felix Geerinckx

on Mon, 26 Aug 2002 12:12:08 GMT, David Samuelsson wrote:

> $_ comes in this form: 
> 
> servername:D:\CC_Storage\Views\EUSDNKG_Madeleine_Tae68_view.vws [uuid
> 74a6b3b0.d1cd11d4.896e.00:b0:d0:83:b4:9b] 
> 
> i want $_ to be just the uuid number that is:
> 74a6b3b0.d1cd11d4.896e.00:b0:d0:83:b4:9b 


s/.*\[uuid (.*)\]/$1/;

-- 
felix

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Regexp

2002-08-26 Thread Robin Norwood

"David Samuelsson (PAC)" <[EMAIL PROTECTED]> writes:

> more regexps..
> 
> $_ comes in this form: 
> 
> servername:D:\CC_Storage\Views\EUSDNKG_Madeleine_Tae68_view.vws [uuid 
>74a6b3b0.d1cd11d4.896e.00:b0:d0:83:b4:9b]
> 
> i want $_ to be just the uuid number that is: 
>74a6b3b0.d1cd11d4.896e.00:b0:d0:83:b4:9b
> 
> how do i get that the easiest way? all $_ are the same they are all within brackets 
>[text here variables, exept . and :]
> 
> //Dave

'
m/\[uuid\s+(.*)\]/;

my $uuid = $1;
'

Should be sufficient.

-RN

-- 

Robin Norwood
Red Hat, Inc.

"The Sage does nothing, yet nothing remains undone."
-Lao Tzu, Te Tao Ching

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Regexp

2002-08-26 Thread david

Felix Geerinckx wrote:

> on Mon, 26 Aug 2002 12:12:08 GMT, David Samuelsson wrote:
> 
>> $_ comes in this form:
>> 
>> servername:D:\CC_Storage\Views\EUSDNKG_Madeleine_Tae68_view.vws [uuid
>> 74a6b3b0.d1cd11d4.896e.00:b0:d0:83:b4:9b]
>> 
>> i want $_ to be just the uuid number that is:
>> 74a6b3b0.d1cd11d4.896e.00:b0:d0:83:b4:9b
> 
> 
> s/.*\[uuid (.*)\]/$1/;

this might be a bit faster:

/(\S+).$/

david



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Regexp

2002-08-26 Thread Felix Geerinckx

on Mon, 26 Aug 2002 19:01:27 GMT, David wrote:

> Felix Geerinckx wrote:

>> s/.*\[uuid (.*)\]/$1/;
> 
> this might be a bit faster:
> 
> /(\S+).$/

If you claim something is faster, prove it ;-)
(But remember, the OP wanted the result in $_).

-- 
felix

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Regexp

2002-08-26 Thread david

Felix Geerinckx wrote:

> on Mon, 26 Aug 2002 19:01:27 GMT, David wrote:
> 
>> Felix Geerinckx wrote:
> 
>>> s/.*\[uuid (.*)\]/$1/;
>> 
>> this might be a bit faster:
>> 
>> /(\S+).$/
> 
> If you claim something is faster, prove it ;-)
> (But remember, the OP wanted the result in $_).
> 

i only suggest that it might be faster. :-)
i won't go into too much detail to try to prove that. i only ran the 
following:

#!/usr/bin/perl -w
use strict;
use Benchmark;

my @t = timethese(99,{'search_assign'   =>
   '$_ = \'vws [uuid 1234.abcd]\';($_) = /(\S+).$/;',
  'search_replace'  =>
   '$_ = \'vws [uuid 1234.abcd]\';s/.*\[uuid (.*)\]/$1/;'});

gives:

Benchmark: timing 99 iterations of search_assign, search_replace...
search_assign: 21 wallclock secs (10.22 usr +  0.00 sys = 10.22 CPU) @ 
97847.26/s (n=99)
search_replace: 34 wallclock secs (16.49 usr +  0.02 sys = 16.51 CPU) @ 
60569.29/s (n=99)

search_assign:  ($_) = /(\S+).$/;
search_replace: s/.*\[uuid (.*)\]/$1/;

david

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Regexp

2002-08-26 Thread Felix Geerinckx

on Mon, 26 Aug 2002 19:53:44 GMT, David wrote:

> Felix Geerinckx wrote:
> 
>> If you claim something is faster, prove it ;-)
>> (But remember, the OP wanted the result in $_).
>> 
> 
> i only suggest that it might be faster. :-)
> i won't go into too much detail to try to prove that. i only ran the 
> following:
> 
> #!/usr/bin/perl -w
> use strict;
> use Benchmark;
> 
> my @t = timethese(99,{'search_assign'   =>
>'$_ = \'vws [uuid 1234.abcd]\';($_) = /(\S+).$/;',
>   'search_replace'  =>
>'$_ = \'vws [uuid 1234.abcd]\';s/.*\[uuid (.*)\]/$1/;'});
> 
> gives:
> 
> Benchmark: timing 99 iterations of search_assign, search_replace...
> search_assign: 21 wallclock secs (10.22 usr +  0.00 sys = 10.22 CPU) @ 
> 97847.26/s (n=99)
> search_replace: 34 wallclock secs (16.49 usr +  0.02 sys = 16.51 CPU) @ 
> 60569.29/s (n=99)

Now you're talking.
But just for the fun of it, run the benchmark again with the OP's original 
(much longer) string ... ;-)

-- 
felix

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Regexp

2002-08-26 Thread david

Felix Geerinckx wrote:
>
> Now you're talking.
> But just for the fun of it, run the benchmark again with the OP's original
> (much longer) string ... ;-)
>

i will do that a bit later. :-) busy doing something else...
yes, the reason why the string is much shorter is becasue i am lazy to 
type... believe it or not, my news reader do not allow(for some unknown 
reason) me to copy and paste outside of it's own window!

david 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Regexp

2002-08-26 Thread Robin Norwood

david <[EMAIL PROTECTED]> writes:

> Felix Geerinckx wrote:
> >
> > Now you're talking.
> > But just for the fun of it, run the benchmark again with the OP's original
> > (much longer) string ... ;-)
> >
> 
> i will do that a bit later. :-) busy doing something else...
> yes, the reason why the string is much shorter is becasue i am lazy to 
> type... believe it or not, my news reader do not allow(for some unknown 
> reason) me to copy and paste outside of it's own window!

>From david's headers:

User-Agent: KNode/0.7.1

Time to change news readers, I think... :-)

-RN

-- 

Robin Norwood
Red Hat, Inc.

"The Sage does nothing, yet nothing remains undone."
-Lao Tzu, Te Tao Ching

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Regexp

2002-08-26 Thread David Zhuo

yeah, i know. :-) as soon as i have time...

david

> >From david's headers:
> 
> User-Agent: KNode/0.7.1
> 
> Time to change news readers, I think... :-)
> 
> -RN
> 
> -- 
> 
> Robin Norwood
> Red Hat, Inc.
> 
> "The Sage does nothing, yet nothing remains undone."
> -Lao Tzu, Te Tao Ching


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Regexp

2002-08-26 Thread david

Robin Norwood wrote:
> From david's headers:
> 
> User-Agent: KNode/0.7.1
> 
> Time to change news readers, I think... :-)
> 
> -RN
> 

just curious. what news reader you guys are using?

david


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Regexp

2002-08-26 Thread Felix Geerinckx

on Mon, 26 Aug 2002 20:46:49 GMT, David wrote:

> Robin Norwood wrote:
>> From david's headers:
>> 
>> User-Agent: KNode/0.7.1
> 
> just curious. what news reader you guys are using?
> 
> david

>From my headers: 

User-Agent: Xnews/5.02.24

(That's on win32. If you're on Linux, you may want to give Mozilla a 
look.)

-- 
felix

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Regexp

2002-08-26 Thread Robin Norwood

david <[EMAIL PROTECTED]> writes:

> Robin Norwood wrote:
> > From david's headers:
> > 
> > User-Agent: KNode/0.7.1
> > 
> > Time to change news readers, I think... :-)
> > 
> > -RN
> > 
> 
> just curious. what news reader you guys are using?

[rnorwood@robin perl-beginners]$ perl -le 'my %r;while (<>) {$r{$1}++ if 
/^User-Agent:\s+([^\/]*)/} foreach my $k (sort keys %r) {print "$k - $r{$k}"}' *

Gnus - 40
Internet Messaging Program (IMP) 3.0
 - 1
KMail - 12
KNode - 48
Messenger-Pro - 3
Microsoft-Entourage - 5
Microsoft-Outlook-Express-Macintosh-Edition - 1
Mozilla - 55
Mutt - 122
Pan - 54
Xnews - 97
tin - 21


That's message counts, not user counts...I'm too lazy to count users.
And it's only since I subscribed earlier this month.  :-)

Personally, I'm using Gnus (http://my.gnus.org/), which works quite
well - however, it runs under Emacs, and the learning curve is a bit
steep, so I'd only recommend it if you love Emacs, and have a day to
spend getting the thing to work and learning the keybindings... :-)

-RN

-- 

Robin Norwood
Red Hat, Inc.

"The Sage does nothing, yet nothing remains undone."
-Lao Tzu, Te Tao Ching

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Regexp

2002-08-26 Thread david

Felix Geerinckx wrote:
>
> Now you're talking.
> But just for the fun of it, run the benchmark again with the OP's original
> (much longer) string ... ;-)
>

testing result for a longer string(i use the one from the OP).i add a few 
new lines to make it more readable:

Benchmark: timing 99 iterations of search_assign, search_replace, 
substr...

search_assign: 51 wallclock secs (22.73 usr +  0.02 sys = 22.75 CPU) @ 
43956.00/s (n=99)

search_replace: 37 wallclock secs (17.29 usr +  0.01 sys = 17.30 CPU) @ 
57803.41/s (n=99)

substr: 10 wallclock secs ( 4.40 usr +  0.00 sys =  4.40 CPU) @ 
227272.50/s (n=99)

essentially:

search_assign is:   ($_) = /(\S+).$/;
search_replace: is: s/.*\[uuid (.*)\]/$1/;
substr is:  ($_ = substr($_,rindex($_,' ')+1)) =~ s/.$//;

so for a shorter string, the search_assign thingy is faster. for a longer 
string the search_replace appoach is faster.

but in all cases, the substr appoach is faster(sometimes much faster) than 
the other appocach... nice to know.

david


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Regexp

2002-08-26 Thread David Zhuo

thanks for providing the stat. it's very nice.

unfortunately, i use vi exclusively and don't like to touch Emacs at all
:-)

david

On Mon, 2002-08-26 at 14:18, Robin Norwood wrote:
> david <[EMAIL PROTECTED]> writes:
> 
> > Robin Norwood wrote:
> > > From david's headers:
> > > 
> > > User-Agent: KNode/0.7.1
> > > 
> > > Time to change news readers, I think... :-)
> > > 
> > > -RN
> > > 
> > 
> > just curious. what news reader you guys are using?
> 
> [rnorwood@robin perl-beginners]$ perl -le 'my %r;while (<>) {$r{$1}++ if 
>/^User-Agent:\s+([^\/]*)/} foreach my $k (sort keys %r) {print "$k - $r{$k}"}' *
> 
> Gnus - 40
> Internet Messaging Program (IMP) 3.0
>  - 1
> KMail - 12
> KNode - 48
> Messenger-Pro - 3
> Microsoft-Entourage - 5
> Microsoft-Outlook-Express-Macintosh-Edition - 1
> Mozilla - 55
> Mutt - 122
> Pan - 54
> Xnews - 97
> tin - 21
> 
> 
> That's message counts, not user counts...I'm too lazy to count users.
> And it's only since I subscribed earlier this month.  :-)
> 
> Personally, I'm using Gnus (http://my.gnus.org/), which works quite
> well - however, it runs under Emacs, and the learning curve is a bit
> steep, so I'd only recommend it if you love Emacs, and have a day to
> spend getting the thing to work and learning the keybindings... :-)
> 
> -RN
> 
> -- 
> 
> Robin Norwood
> Red Hat, Inc.
> 
> "The Sage does nothing, yet nothing remains undone."
> -Lao Tzu, Te Tao Ching



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Regexp

2002-08-26 Thread John W. Krahn

Robin Norwood wrote:
> 
> david <[EMAIL PROTECTED]> writes:
> 
> > Felix Geerinckx wrote:
> > >
> > > Now you're talking.
> > > But just for the fun of it, run the benchmark again with the OP's original
> > > (much longer) string ... ;-)
> > >
> >
> > i will do that a bit later. :-) busy doing something else...
> > yes, the reason why the string is much shorter is becasue i am lazy to
> > type... believe it or not, my news reader do not allow(for some unknown
> > reason) me to copy and paste outside of it's own window!
> 
> From david's headers:
> 
> User-Agent: KNode/0.7.1
> 
> Time to change news readers, I think... :-)

Time to learn how to copy and paste in X, I think... :-)

Hint:  Hilite any text in Xterm, Mozilla, Knode, etc. and use the middle
mouse button (or chord the left and right buttons) and the hilited text
will appear at the text cursor in the current window.



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Regexp

2002-08-26 Thread david

John W. Krahn wrote:
> 
> Time to learn how to copy and paste in X, I think... :-)
> 

Thanks but i *think* i know how to copy and paste in X  :o
but then why am i still struggling copying from KNote to vim...

since this is off topic a bit, let's kill it now. otherwise, the list master 
might not be happy.

david

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Regexp

2002-08-27 Thread alex chen


"David Samuelsson" <[EMAIL PROTECTED]>
??:[EMAIL PROTECTED]
...
> more regexps..
>
> $_ comes in this form:
>
> servername:D:\CC_Storage\Views\EUSDNKG_Madeleine_Tae68_view.vws [uuid
74a6b3b0.d1cd11d4.896e.00:b0:d0:83:b4:9b]
>
> i want $_ to be just the uuid number that is:
74a6b3b0.d1cd11d4.896e.00:b0:d0:83:b4:9b
>
> how do i get that the easiest way? all $_ are the same they are all within
brackets [text here variables, exept . and :]
>
> //Dave
>
>
i think this is more efficiency
eg.
 $a = "servername:D:\CC_Storage\Views\EUSDNKG_Madeleine_Tae68_view.vws [uuid
74a6b3b0.d1cd11d4.896e.00:b0:d0:83:b4:9b]";
 @a = split (/\[uuid/,$a);
chop($a[1]);



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Regexp

2002-09-18 Thread Ramprasad A Padmanabhan

This may not be the best way But I wud work fine

sub remove_space {
my($s)=@_;
$s=~s/\s+//g;
return $s;
}

while(){
s/^(.*?)\s+(.*)$/$1.remove_space($2)/
 print;

}




Panel Vincent - A53 wrote:
> I have a problem with a regular expression :
> 
> I process a text file with a list of names.
> 
> I would like to reformat names like
> 
>   Francois de   la Varenne
> Macha Meril 
> BuzzMac Cormack
> 
> (there must be at least two words in the name)
> to something like this :
> 
> [EMAIL PROTECTED]
> [EMAIL PROTECTED]
> [EMAIL PROTECTED]
> 
> In other words : "[EMAIL PROTECTED]".
> 
> I tried the following thing and it doesn't work ($name already contains one
> of those names) :
> 
> $name=~s/\s*(\w+)\s+(\w+)(\s+(\w+))*\s*/$1.$2$3\@domain.top/
> 
> 
> Does anyone knows the right regexp to do this (I guess it's the second
> expression with $s which is wrong)
> 
> Vincent Panel.



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Regexp

2002-09-18 Thread Ramprasad A Padmanabhan

oops sorry put an 'e' after the regexp in the end

Ramprasad A Padmanabhan wrote:
> This may not be the best way But I wud work fine
> 
> sub remove_space {
> my($s)=@_;
> $s=~s/\s+//g;
> return $s;
> }
> 
> while(){
> s/^(.*?)\s+(.*)$/$1.remove_space($2)/
>  print;
> 
> }
> 
> 
> 
> 
> Panel Vincent - A53 wrote:
> 
>> I have a problem with a regular expression :
>>
>> I process a text file with a list of names.
>>
>> I would like to reformat names like
>>
>>   Francois de   la Varenne
>> Macha Meril BuzzMac Cormack
>>
>> (there must be at least two words in the name)
>> to something like this :
>>
>> [EMAIL PROTECTED]
>> [EMAIL PROTECTED]
>> [EMAIL PROTECTED]
>>
>> In other words : "[EMAIL PROTECTED]".
>>
>> I tried the following thing and it doesn't work ($name already 
>> contains one
>> of those names) :
>>
>> $name=~s/\s*(\w+)\s+(\w+)(\s+(\w+))*\s*/$1.$2$3\@domain.top/
>>
>>
>> Does anyone knows the right regexp to do this (I guess it's the second
>> expression with $s which is wrong)
>>
>> Vincent Panel.
> 
> 
> 



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Regexp

2002-09-18 Thread Panel Vincent - A53

> Why not splitting on whitespaces and joining the pieces together ? E.g.

Because it won't work : "michael mac douglas" will give
"[EMAIL PROTECTED]" not "[EMAIL PROTECTED]"

Vincent.

> -Original Message-
> From: Thorsten Dieckhoff [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, September 18, 2002 2:47 PM
> To: Panel Vincent - A53
> Subject: Re: Regexp
> 
> 
> > I have a problem with a regular expression :
> >
> > I process a text file with a list of names.
> >
> > I would like to reformat names like
> >
> >   Francois de   la Varenne
> > Macha Meril
> > BuzzMac Cormack
> >
> > (there must be at least two words in the name)
> > to something like this :
> >
> > [EMAIL PROTECTED]
> > [EMAIL PROTECTED]
> > [EMAIL PROTECTED]
> >
> > In other words : "[EMAIL PROTECTED]".
> >
> > I tried the following thing and it doesn't work ($name already
> contains one
> > of those names) :
> >
> > $name=~s/\s*(\w+)\s+(\w+)(\s+(\w+))*\s*/$1.$2$3\@domain.top/
> >
> >
> > Does anyone knows the right regexp to do this (I guess it's the
> second
> > expression with $s which is wrong)
> >
> > Vincent Panel.
> 
> Hi, I assume you have one full name per line - why not splitting on
> whitespaces
> and joining the pieces together ? E.g.
> 
> @names = split(/\s/, $line);
> $fullname = join('.', @names) . '@my.domain.foo';
> 
> HTH, Thorsten !
> 
> 
> 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Regexp

2002-09-18 Thread Sudarshan Raghavan

On Wed, 18 Sep 2002, Panel Vincent - A53 wrote:

> I have a problem with a regular expression :
> 
> I process a text file with a list of names.
> 
> I would like to reformat names like
> 
>   Francois de   la Varenne
> Macha Meril 
> BuzzMac Cormack
> 
> (there must be at least two words in the name)
> to something like this :
> 
> [EMAIL PROTECTED]
> [EMAIL PROTECTED]
> [EMAIL PROTECTED]
> 
> In other words : "[EMAIL PROTECTED]".
> 
> I tried the following thing and it doesn't work ($name already contains one
> of those names) :
> 
> $name=~s/\s*(\w+)\s+(\w+)(\s+(\w+))*\s*/$1.$2$3\@domain.top/

Use split instead of a regexp (perldoc -f split)
Let us assume the input string is in $str, this should do the job for you

my ($first, $rest) = split (/\s+/, $str, 2);
$rest =~ s/\s+//g;
print "$first.$last\@domain.top";



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Regexp

2002-09-18 Thread Jeff AA


> -Original Message-
> From: Sudarshan Raghavan [mailto:[EMAIL PROTECTED]] 
> Sent: 19 September 2002 23:57
> To: Perl beginners
> Subject: Re: Regexp
> 
> 
> On Wed, 18 Sep 2002, Panel Vincent - A53 wrote:
> 
> > I would like to reformat names like
> > 
> >   Francois de   la Varenne
> > Macha Meril 
> > BuzzMac Cormack
> > 

> Use split instead of a regexp (perldoc -f split)
> Let us assume the input string is in $str, this should do the 
> job for you
> 
> my ($first, $rest) = split (/\s+/, $str, 2);
> $rest =~ s/\s+//g;
> print "$first.$last\@domain.top";
> 

split is the best way, but above split leads to empty leading values
> >   Francois de   la Varenne
would end up [EMAIL PROTECTED]


the following should work: (the split pattern is a one character space
rather than a regex)

my @words = split ' ', $name;
my $email = shift(@words) . '.' . join('',@words) . '@domain.top';
print "'$name' => '$email'\n";

--or--

my @words = split ' ', $name, 2;
my $email = $words[0] . '.' . $words[1] . '@domain.top';
$email =~ s/\s+//g;
print "'$name' => '$email'\n";


regards
Jeff


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Regexp

2002-09-18 Thread John W. Krahn

Sudarshan Raghavan wrote:
> 
> On Wed, 18 Sep 2002, Panel Vincent - A53 wrote:
> 
> > I have a problem with a regular expression :
> >
> > I process a text file with a list of names.
> >
> > I would like to reformat names like
> >
> >   Francois de   la Varenne
> > Macha Meril
> > BuzzMac Cormack
> >
> > (there must be at least two words in the name)
> > to something like this :
> >
> > [EMAIL PROTECTED]
> > [EMAIL PROTECTED]
> > [EMAIL PROTECTED]
> >
> > In other words : "[EMAIL PROTECTED]".
> >
> > I tried the following thing and it doesn't work ($name already contains one
> > of those names) :
> >
> > $name=~s/\s*(\w+)\s+(\w+)(\s+(\w+))*\s*/$1.$2$3\@domain.top/
> 
> Use split instead of a regexp (perldoc -f split)
> Let us assume the input string is in $str, this should do the job for you
> 
> my ($first, $rest) = split (/\s+/, $str, 2);
> $rest =~ s/\s+//g;
> print "$first.$last\@domain.top";


Very good.  Don't forget the OP wants it converted to lower case as
well.  :-)

my ( $first, $rest ) = map lc, split ' ', $str, 2;
$rest =~ s/\s+//g;
print "$first.$last\@domain.top";



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Regexp

2002-09-19 Thread Panel Vincent - A53

Thank you all for your very accurate answers.

Vincent.

> -Original Message-
> From: John W. Krahn [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, September 18, 2002 7:08 PM
> To: [EMAIL PROTECTED]
> Subject: Re: Regexp
> 
> 
> Sudarshan Raghavan wrote:
> > 
> > On Wed, 18 Sep 2002, Panel Vincent - A53 wrote:
> > 
> > > I have a problem with a regular expression :
> > >
> > > I process a text file with a list of names.
> > >
> > > I would like to reformat names like
> > >
> > >   Francois de   la Varenne
> > > Macha Meril
> > > BuzzMac Cormack
> > >
> > > (there must be at least two words in the name)
> > > to something like this :
> > >
> > > [EMAIL PROTECTED]
> > > [EMAIL PROTECTED]
> > > [EMAIL PROTECTED]
> > >
> > > In other words : "[EMAIL PROTECTED]".
> > >
> > > I tried the following thing and it doesn't work ($name 
> already contains one
> > > of those names) :
> > >
> > > $name=~s/\s*(\w+)\s+(\w+)(\s+(\w+))*\s*/$1.$2$3\@domain.top/
> > 
> > Use split instead of a regexp (perldoc -f split)
> > Let us assume the input string is in $str, this should do 
> the job for you
> > 
> > my ($first, $rest) = split (/\s+/, $str, 2);
> > $rest =~ s/\s+//g;
> > print "$first.$last\@domain.top";
> 
> 
> Very good.  Don't forget the OP wants it converted to lower case as
> well.  :-)
> 
> my ( $first, $rest ) = map lc, split ' ', $str, 2;
> $rest =~ s/\s+//g;
> print "$first.$last\@domain.top";
> 
> 
> 
> John
> -- 
> use Perl;
> program
> fulfillment
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Repeating Regexp

2002-11-28 Thread Paul Murphy


Hello, this is a two part question: a how to, and a how best to.

I have a string of numbers:

"2329238023089823"

And I want insert a space after each number.  I can see how to insert 
after the first:

s/(\d)/$1 /

Can any one tell me how I can get the regexp to continue through the 
string and insert spaces throughout?

The next part of the question is, given the above string, what is the 
best way of displaying the string with the added spaces, without 
necessarily altering it in the variable?

So if the first part of the question is answered, then that is one way of 
doing it, but are there better ways (there are *always* better ways :-) )?

Thanks,

Paul.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Regexp help

2004-01-24 Thread Marcelo
Which regular expression would you use to remove the  and  from a line 
like this one:

Here goes a webpage's title

Thanks a lot in advance.


Perl: regexp

2004-02-24 Thread Rajan
Hi Experts,

  I am new to perl. The following code works fine.

#!/opt/perl/bin/perl
use strict;
use warnings;

my $str="http://162.16.23.0";;
if( $str =~ /(\d+)\.(\d+)\.(\d+)\.(\d+)/ )
{
print "$1.$2.$3.$4";
}

But, How to simplify the following line & print the IP in the above code?.

$str =~ /(\d+)\.(\d+)\.(\d+)\.(\d+)/ 

Thanks,
Rajan.



---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.592 / Virus Database: 375 - Release Date: 2/19/2004

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




RegExp Help !

2004-05-10 Thread amjoe11-3
Hi Gurus !

Well need your help in framing a RegExp

I've to parse for the  tag in a HTML/ASP file and then when i get that i need
to get only yhe action filepath in to an array ! How do i do it ?

For Example 



i need only the "register/doregister.asp" in an array !

Please Help.

Thanks in Advance
Joe

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Re: regexp

2004-05-19 Thread JupiterHost.Net
Graf Laszlo wrote:
Hi
Hello,
I have the following HTML structure:
Looks more like XML...


BBB


CCC


Every line in this structure is an element of an array,
named @lines, and I access the elements using a foreach loop.
When I know the tag's name, by example 'sm:a',
and I need to extract the information contained by ''
and '' pair and the tags too, how should I proceed ?
I recommend trying an XML parsing module from search.cpan.org
HTH :)
Lee.M - JupiterHost.Net
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: regexp

2004-05-19 Thread James Edward Gray II
On May 19, 2004, at 9:52 AM, Graf Laszlo wrote:
Hi
I have the following HTML structure:


BBB


CCC


Every line in this structure is an element of an array,
named @lines, and I access the elements using a foreach loop.
When I know the tag's name, by example 'sm:a',
and I need to extract the information contained by ''
and '' pair and the tags too, how should I proceed ?
Not totally sure I understand, but let's see if this gets you going:
my $tags = join '', @lines;
print "$1\n" if $tags =~ m/(.*?)<\/sm:a>/s;
Hope that helps.
James
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: regexp

2004-05-19 Thread Jose Alves de Castro
On Wed, 2004-05-19 at 15:52, Graf Laszlo wrote:
> Hi

Hi

> I have the following HTML structure:
> 
> 
>   
>   BBB
>   
>   
>   CCC
>   
> 
> 
> Every line in this structure is an element of an array,
> named @lines, and I access the elements using a foreach loop.
> 
> When I know the tag's name, by example 'sm:a',
> and I need to extract the information contained by ''
> and '' pair and the tags too, how should I proceed ?
> I tried a regexp like this:
> 
> foreach $s (@lines) {
> print "$s";
> if($s =~ m|^(\\n)(.*?)(\\n<\/sm:a>)$|s){
>($l,$c,$r) = ($1,$2,$3);
>print "OK\n";
>print "l: '$l'\n";
>print "c: '$c'\n";
>print "r: '$r'\n";
> }else{
>print "HEHE\n";
> }
> }

The problem is that your expression is supposed to be applied to the
whole text, but you're applying it to each line at a time.

Try this:

for (@lines) {
  if ( // .. /<\/sm:a>/ )
  {
print
  }
}

> Help me. Thank you.

HTH,

jac

-- 
Josà Alves de Castro <[EMAIL PROTECTED]>
Telbit - Tecnologias de InformaÃÃo


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




RE: Regexp

2004-05-28 Thread Wagner, David --- Senior Programmer Analyst --- WGO
[EMAIL PROTECTED] wrote:
> I have the following lines:
> 
> g00:~> perl -e '
> $a = "aa** a";
Since you have * which in a regex stands for zero or more occurances, then you 
must turn this off as part of the processing. You use \Q and \E as in /^\Q$b\E/ would 
take the aa** a as just that.

I would get away from the $a and $b as variables since this are default 
variables for sort and can cause you problems in the future if not careful.

Wags ;)

> $b = $a;
> $b =~ qw/$b/;
> print "Yes\n" if $a =~ /^$b/;
> print $b'
> Nested quantifiers in regex; marked by <-- HERE in m/^aa** <-- HERE 
> a/ at -e line 5.
> 
> Is there a way to make the regexp takes '$b' as string, because
> I see the non characters are problem.
> 
> Thanks
> 
> -
> This mail is from: <[EMAIL PROTECTED]>
> -



  Any questions and/or problems, please let me know.

  Thanks.

Wags ;)
Int: 9-8-002-2224
Ext: 408-323-4225x2224



***
This message conatains information that is confidential
and proprietary to FedEx Freight or its affiliates.
It is intended only for the recipient named and for
the express purpose(s) described therein.
Any other use is prohibited.
***


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




RE: Regexp

2004-06-19 Thread Tim Johnson

This sounds like a homework project.  We don't generally do people's
homework for them.  If I'm wrong, I apologize.  Maybe you can tell us
what you've tried so far.  Have you read through 'perldoc perlre'?

I would recommend the module YAPE::Regex::Explain if you want some help
figuring out what your regular expressions are really doing.

-Original Message-
From: Mandar Rahurkar [mailto:[EMAIL PROTECTED] 
Sent: Saturday, June 19, 2004 5:48 PM
Cc: [EMAIL PROTECTED]
Subject: Regexp

Hi All,
   what wud be the regexp for :

1. substituting last s of every word 
   e.g., forests become forest,  goats becomes goat

2. removing all one and two lettered words 
   e.g., a,an



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




RE: Regexp

2004-06-19 Thread Mandar Rahurkar
Hi,
   I am too old to have homeworks on perl :)
I tried for the first case:
s/\ws\b/$1/;

but trick to understand is that I need to substitute forests with forest. 
I can probably use substr however was looking for a elegant solution.

Mandar


On Sat, 19 Jun 2004, Tim Johnson wrote:

> 
> This sounds like a homework project.  We don't generally do people's
> homework for them.  If I'm wrong, I apologize.  Maybe you can tell us
> what you've tried so far.  Have you read through 'perldoc perlre'?
> 
> I would recommend the module YAPE::Regex::Explain if you want some help
> figuring out what your regular expressions are really doing.
> 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




RE: Regexp

2004-06-19 Thread Tim Johnson

What about:

$string =~ s/s\b//g;

-Original Message-
From: Mandar Rahurkar [mailto:[EMAIL PROTECTED] 
Sent: Saturday, June 19, 2004 8:06 PM
To: Tim Johnson
Cc: [EMAIL PROTECTED]
Subject: RE: Regexp

Hi,
   I am too old to have homeworks on perl :)
I tried for the first case:
s/\ws\b/$1/;

but trick to understand is that I need to substitute forests with
forest. 
I can probably use substr however was looking for a elegant solution.

Mandar


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




RE: Regexp

2004-06-19 Thread Tim Johnson

And for #2, how about:

s/\b\w{1,2}\b//g;

-Original Message-
From: Mandar Rahurkar [mailto:[EMAIL PROTECTED] 
Sent: Saturday, June 19, 2004 5:48 PM
Cc: [EMAIL PROTECTED]
Subject: Regexp



2. removing all one and two lettered words 
   e.g., a,an



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




RegExp help

2004-06-24 Thread Price, Jason (TLR Corp)
I'm trying to write a regular expression to divide up a line of text
into a hash, but am having a hard time with it.  I'm hoping you all can
help me.

Here's an example line of text:

"( uiwgAttribute-OID NAME 'uiwgAttribute' DESC 'Contains meta data about
an attribute' SUP top MUST cn MAY ( uiwgADsType $ uiwgDescription $
uiwgDisplayName $ uiwgIsMultiValued ) )"

Each line is similar, yet different.  :)  Basically, I want to divide
each line up into a hash, with the keys being the words in all caps, and
the values being the text after the key (up until the next key or
end-of-line).  So, the above example would become (logically):

%hash {
NAME -> 'uiwgAttribute',
DESC -> 'Contains meta data about an attribute',
SUP -> 'top',
MUST -> 'cn',
MAY -: '( uiwgADsType $ uiwgDescription $ uiwgDisplayName $
uiwgIsMultiValued )'
}

Not every line will have the same keys, or the same number of keys.  Is
there a good way to do this with a regular expression?

Thanks.

Jason

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




regexp cleanup

2004-07-02 Thread Laurent Coudeur
Hi,

Trying to clean up a mass of replacement

here is a small bit

$export=~s/\\'F5/õ/gi;
$export=~s/\\'F6/ö/gi;
$export=~s/\\'F7/÷/gi;
$export=~s/\\'F8/ø/gi;
$export=~s/\\'F9/ù/gi;
$export=~s/\\'FA/ú/gi;
$export=~s/\\'FB/û/gi;
$export=~s/\\'FC/ü/gi;

I'd need some pointers on How to tidy the mess (that script is turning into a 
nightmare and I'm running out of braincells)

Laurent Coudeur
353 1 212 3181 

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: regexp

2003-08-26 Thread Ramprasad A Padmanabhan
Anton Arhipov wrote:
Hi,

i've a string like "BLAH" (guotes included).
i need to control if the BLAH is in uppercase and then if it is in 
uppercase truncate the quotes ("), so "BLAH" becomes BLAH.

any solutions?

Thx


You mean If you find any upper case word within quotes remove quotes right ?

$str = 'abc "BLAH" aaa "eef" ';
print "$str\n";
$str=~s/\"([^\"]+)\"/{(uc($1) eq $1)?$1:"\"$1\"";}/ge;
print "$str\n";
This should work
Ram






--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: regexp

2003-08-26 Thread Janek Schleicher
Anton Arhipov wrote at Tue, 26 Aug 2003 13:02:00 +0300:

> i've a string like "BLAH" (guotes included).
> i need to control if the BLAH is in uppercase and then if it is in 
> uppercase truncate the quotes ("), so "BLAH" becomes BLAH.

s/"([A-Z]+)"/$1/g;

or on a POSIX operating system I would prefer the more appropriate
character class

s/"([[:upper:]]+)"/$1/g;


Greetings,
Janek

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Regexp tester

2002-04-11 Thread Babichev Dmitry

Hello, beginners.

Sorry to trouble you.

Is anybody use any free Regexp tester?
Like in the OptiPerl - but it's non-free... :(


Thank you in advance.
Babichev L. Dmitry


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Regexp

2002-05-09 Thread Jonathan E. Paton

> I have a lot of trouble understanding regexes, i just don't get how to parse
> a file with:
> 
> "Hablar es el arte de sofocar e interrumpir el pensamiento". Thomas Carlyle
> (1795-1881); historiador y ensayista escocés.
> "Se aprende más por lo que la gente habla entre sí o por lo que se
> sobrentiende, que planteándose preguntas". Rudyard Kipling (1865-1936);
> escritor inglés, de origen indio.
> "Hay palabras que suben como el humo, y otras que caen como la lluvia".
> Marquesa de Sévigné,(1626-1696); escritora francesa.
> "El destino es el que baraja las cartas, pero nosotros somos los que
> jugamos". William Shakespeare (1564-1616); poeta y dramaturgo inglés.
> 
> I need to separate for print the quote, then the name and the coments.

my ($quote, $name, $reign, $comment) = $line =~ /^"([^"]*)"\.  # Quote
 ([^\(]+)\(# Name
 ([^\)]+)\)\;  # Reign
 ([^\.]+)\.$/x # Comment

They can get hairy, and that's probably got an error in it.  Basically
you need to know:

^means start of line
$means end of line
()   means capture and store in a magic variable ($1, $2, ...)
[]   means a character group (called a 'class')
[^]  means an inverted character class, which is anything that isn't 
 these characters

The /x at the end allows me to put in comments, good luck!

Jonathan Paton

=
---BEGIN GEEKCODE BLOCK---v3.12
GCS/E d+ s+: a20 C++(+++)>$ UHL++>+++ P+++ L++>
E- W++(-) N+ o? K- w--- !O M-- !V PS-- PE++ Y++ PGP
t@ 5-- X-- R- tv- b  DI+ D- G++ e h! !r--->++ !y---
END GEEKCODE BLOCK-
JAPH: print`perldoc perlembed`=~/(Ju.*)/,"\n"

__
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Regexp

2002-05-09 Thread Wagner-David

Here is one shot.

Wags 

=

Script starts after this line.
#!perl -w
y @MyInfo = ();
while (  ) {
   chomp;
   next if ( /^\s*$/ ); # Bypass any blanklines
   if ( ! /^\"([^"]+)\"\.\s+([^]+);(.+)/i ) { # If line starts w/ " then
grab all between " into $1
  # Then should be
". and one or more spaces
  # pull all that is
not a : into $2
# Then a ; and the
rest into $3
  printf "Expecting input as \"quote\". author;comments, but
received\n<$_>\n";
  next;
}
   push( @MyInfo, [ $1,$2,$3]);   # push into #MyInfo as double
index array
  # [x][0] = quote
  # [x][1] = Author
  # [x][2] =
Comments
 }
for(my $MyId=0;$MyId<=$#MyInfo;$MyId++) {   # pull out the data and
print
   printf "Quote: %-s\nAuthor: %-s\nComments: %-s\n", $MyInfo[$MyId][0], 
  $MyInfo[$MyId][1],
  $MyInfo[$MyId][2];
 }
__DATA__
"Hablar es el arte de sofocar e interrumpir el pensamiento". Thomas Carlyle
(1795-1881); historiador y ensayista escocés.
"Se aprende más por lo que la gente habla entre sí o por lo que
sesobrentiende, que planteándose preguntas". Rudyard Kipling (1865-1936);
escritor inglés, de origen indio.
"Hay palabras que suben como el humo, y otras que caen como la lluvia".
Marquesa de Sévigné,(1626-1696); escritora francesa.
"El destino es el que baraja las cartas, pero nosotros somos los
quejugamos". William Shakespeare (1564-1616); poeta y dramaturgo inglés.
^-- Script ends here

Output:
Quote: Hablar es el arte de sofocar e interrumpir el pensamiento
Author: Thomas Carlyle (1795-1881)
Comments:  historiador y ensayista escoc?s.
Quote: Se aprende mßs por lo que la gente habla entre s? o por lo que
sesobrenti
ende, que planteßndose preguntas
Author: Rudyard Kipling (1865-1936)
Comments:  escritor ingl?s, de origen indio.
Quote: Hay palabras que suben como el humo, y otras que caen como la lluvia
Author: Marquesa de S?vign?,(1626-1696)
Comments:  escritora francesa.
Quote: El destino es el que baraja las cartas, pero nosotros somos los
quejugamos
Author: William Shakespeare (1564-1616)
Comments:  poeta y dramaturgo ingl?s.

-Original Message-
From: Eduardo Cancino [mailto:[EMAIL PROTECTED]]
Sent: Thursday, May 09, 2002 12:42
To: List Beginners Perl
Subject: Regexp


Hello!

I have a lot of trouble understanding regexes, i just don't get how to parse
a file with:

"Hablar es el arte de sofocar e interrumpir el pensamiento". Thomas Carlyle
(1795-1881); historiador y ensayista escocés.
"Se aprende más por lo que la gente habla entre sí o por lo que se
sobrentiende, que planteándose preguntas". Rudyard Kipling (1865-1936);
escritor inglés, de origen indio.
"Hay palabras que suben como el humo, y otras que caen como la lluvia".
Marquesa de Sévigné,(1626-1696); escritora francesa.
"El destino es el que baraja las cartas, pero nosotros somos los que
jugamos". William Shakespeare (1564-1616); poeta y dramaturgo inglés.

I need to separate for print the quote, then the name and the coments.

Could someone give me some pointers??

Thanks!


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Regexp

2002-05-09 Thread drieux


On Thursday, May 9, 2002, at 12:41 , Eduardo Cancino wrote:

> Could someone give me some pointers??
>
> Thanks!

both wag and jonathan have provided most excellent regEx's
but their core premise remains that all of the data is always
going to be on one line.
{wags at least has the 'explosion' line:
Expecting input as "quote". author;comments, butreceived
<"Hablar es el arte de sofocar e interrumpir el pensamiento". Thomas 
Carlyle>
to be explicit when it Fragged.}

may I offer the modification to jonathan's regEx that
allows for multiLine data:

http://www.wetware.com/drieux/CS/lang/Perl/Beginners/RegEx/paraHablarRegular.
txt



ciao
drieux

---


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RegExp Problem...

2001-09-18 Thread David Simcik

Hi folks,
I'm stumped...I wrote a test script and this pattern matches just fine, but
when I try to use it in another script it does match as it should.
Basically, if the pattern detects an _ underscore in the string it should
return undef; if it doesn't match it returns true. Here's some code:

if(isFacStaff('xty_1233'))
{
print "Is Faculty/Staff!\n";
}
else
{
print "Is Student!\n";
}


sub isFacStaff
{
my $id = @_;

#this will match student-style ID's
#it is rather easier to match against student IDs than staf IDs
if($id =~ m/^.+_.+$/i)
{
return;
}
else
{
return 1;
}
}

Thanks in advance for any help!
DTS


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




regexp question

2001-10-19 Thread birgit kellner

my $header = "Joe DoeThe book I wrote yesterday";
my $title;
if ($header =~ /(^\S.+)()(\S.+$)/m) { $title = "$1: $3";}
print "$title\n";

Is there a shorter, simpler, more efficient way to do this? I still need 
$header later on as it is.

I quite often have to copy the value of a variable and then run a regexp 
substitution on it; I was wondering whether there's a better approach than 
this one.

Birgit Kellner

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




regexp question

2001-10-22 Thread Jerry Preston

Hi,

I want to break down this name, pgrap.C4A2S1R.1.gif, into 4 parts.  I
can do it with split:

  ( $a1,$a2,$a3,$a4 ) = split( /\./, $program );

How do I do it with   s/\b(\.)\b(\.)\b(\.)\b(\.)/?

Thanks,

Jerry



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




regexp question

2001-10-23 Thread Jerry Preston

Hi,

I want to break down this name, pgrap.C4A2S1R.1.gif, into 4 parts.  I
can do it with split:

  ( $a1,$a2,$a3,$a4 ) = split( /\./, $program );

How do I do it with   s/\b(\.)\b(\.)\b(\.)\b(\.)/?

Thanks,

Jerry





-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




regexp question

2001-11-03 Thread Martin Karlsson

Hi all!

Could anyone give me a push in the right direction, please?
How do I write a regexp that matches double instances of letters (in a
file i read into a variable), e.g. aa LL pp etc. ?

Is there an easy way, or must I use
(aa|bb|cc|... and so on ) ?
Thanks for your time!
-- 

Martin Karlsson [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: regexp

2001-11-13 Thread Wagner-David

You don't need to read the whole file in, but could try somehting like this:

Script starts next line:
#!perl -w
my $counter = 1;
my %headinghash;

while () {
chomp;
if ( /^(\d+)\.\s+(.*)/ ) {
   $counter = $1;
   $Headinghash{$counter} = $2 . "\n";
 }elsif ( ! /${counter}\./ ) {
   $Headinghash{$counter} .= $_ . "\n";
 }else {
   $counter = '';
 }
=head1
if ($file =~ /^($counter)\.\s(.*?)$/) {
$headinghash{$counter} = $2;
#missing code here, need data up to next occurrence of "$counter.1"
$counter++;
}
=cut
}
foreach my $MyKey (sort {$a <=> $b} keys %Headinghash) {
   printf "%2d:\n%-s", $MyKey, $Headinghash{$MyKey};
 }
 
__DATA__
1. This is a heading

1.1. A subheading
1.2. Another subheading
2. Another heading
...
3. Yet another heading
..
^- script ends here

Output:
 1:
This is a heading

 2:
Another heading
...
 3:
Yet another heading
..

-Original Message-
From: birgit kellner [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, November 13, 2001 12:56
To: [EMAIL PROTECTED]
Subject: regexp


I have a file structured like this:

1. This is a heading

1.1. A subheading
1.2. Another subheading
2. Another heading
...
3. Yet another heading
..

I want to extract (a) each heading number with the matching heading text, 
and (b) the immediately following text up to, and not including, the first 
subheading.

I got the first part, but not the second:
my $counter = 1;
my %headinghash;
open (FILE, ") {
my $file = $_;
chomp($file);
if ($file =~ /^($counter)\.\s(.*?)$/) {
$headinghash{$counter} = $2;
#missing code here, need data up to next occurrence of "$counter.1"
$counter++;
}
}
close (FILE);

I need the regexp to take off at that point where there was a match for the 
heading, and then extract everything from there up to the occurrence of 
"$counter.1". Would this necessarily involve slurping the whole file into 
an array first?


Thanks in advance for any advice,

Birgit Kellner



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: regexp

2001-11-14 Thread birgit kellner

Many thanks to "Wagner-David" for the code. I've slightly changed it, as 
below, but have still further questions.

use strict;
my $counter = 1;
my %Headinghash;
my %Texthash;
while () {
chomp;
if ( /^(\d+)\.\s+(.*)/ ) {
   $counter = $1;
   $Headinghash{$counter} = $2;
 }elsif ( ! /${counter}\./ ) {
   $Texthash{$counter} .= $_;
 }else {
   $counter = '';
 }
}
foreach my $MyKey (sort {$a <=> $b} keys %Headinghash) {
   print "HEADING: $MyKey, $Headinghash{$MyKey}\n TEXT: $MyKey, 
$Texthash{$MyKey}\n";
 }

__DATA__
1. This is a heading
text in between ...
1.1. A subheading
... and this is text after subheading 1.1
1.2. Another subheading
2. Another heading
...
3. Yet another heading
..
--- end code -
This works fine for DATA as it is, but unfortunately my requirements are 
more specific.
I would also like to use it for such data as:
__DATA__
1. This is a heading
text in between ...
1. List item 1
2. List item 2
. more text in between
1.1. A subheading
... and this is text after subheading 1.1
1.2. Another subheading
2. Another heading
...
3. Yet another heading
..

-- end data ---
So checking on an initial digit is not specific enough, because in between 
a heading "$counter" and the next subheading "$counter.1", there might be a 
line beginning with "$counter" = a list entry. I really need to do a loop 
moving up a counter, *and* I need the search to be "position-aware".

I guess my question boils down to: How to code "when there's a match of 
"1\.\s" in the beginning of a line, check whether there's a "1\.1\.\s" 
after the end of that line - if so, assign everything in between the end of 
that line and "1\.1\.\s." as a hash value, and move up the counter to 2; if 
not, move up the counter to 2 and search for a line beginning with "2\.\s" 
*after* "1\.1\.\s". "

Birgit Kellner








-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: regexp

2001-11-14 Thread Wagner-David

So given your new data, I am unsure what data would be placed in the hash. 
From your example, what is expected?

Wags ;)

-Original Message-
From: birgit kellner [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, November 14, 2001 02:25
To: [EMAIL PROTECTED]
Cc: Wagner-David
Subject: RE: regexp


Many thanks to "Wagner-David" for the code. I've slightly changed it, as 
below, but have still further questions.

use strict;
my $counter = 1;
my %Headinghash;
my %Texthash;
while () {
chomp;
if ( /^(\d+)\.\s+(.*)/ ) {
   $counter = $1;
   $Headinghash{$counter} = $2;
 }elsif ( ! /${counter}\./ ) {
   $Texthash{$counter} .= $_;
 }else {
   $counter = '';
 }
}
foreach my $MyKey (sort {$a <=> $b} keys %Headinghash) {
   print "HEADING: $MyKey, $Headinghash{$MyKey}\n TEXT: $MyKey, 
$Texthash{$MyKey}\n";
 }

__DATA__
1. This is a heading
text in between ...
1.1. A subheading
... and this is text after subheading 1.1
1.2. Another subheading
2. Another heading
...
3. Yet another heading
..
--- end code -
This works fine for DATA as it is, but unfortunately my requirements are 
more specific.
I would also like to use it for such data as:
__DATA__
1. This is a heading
text in between ...
1. List item 1
2. List item 2
. more text in between
1.1. A subheading
... and this is text after subheading 1.1
1.2. Another subheading
2. Another heading
...
3. Yet another heading
..

-- end data ---
So checking on an initial digit is not specific enough, because in between 
a heading "$counter" and the next subheading "$counter.1", there might be a 
line beginning with "$counter" = a list entry. I really need to do a loop 
moving up a counter, *and* I need the search to be "position-aware".

I guess my question boils down to: How to code "when there's a match of 
"1\.\s" in the beginning of a line, check whether there's a "1\.1\.\s" 
after the end of that line - if so, assign everything in between the end of 
that line and "1\.1\.\s." as a hash value, and move up the counter to 2; if 
not, move up the counter to 2 and search for a line beginning with "2\.\s" 
*after* "1\.1\.\s". "

Birgit Kellner







-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




  1   2   3   4   5   6   7   8   9   10   >