Re: Regular Expression Help.

2015-03-25 Thread Frank Vino
Thanks a lot Simon

-Frank

On Wed, Mar 25, 2015 at 5:44 PM, Simon Reinhardt 
wrote:

> Hi Frank,
>
> when first learning regexps I read the section "In the World of Regular
> Expressions" in the Lama-Book [1]. If you find this introduction to
> slow, you might also take a look at chromatic's Modern Perl, which is
> available for free [2].
>
> Regards, Simon
>
> Am 25.03.2015 um 06:01 schrieb Frank Vino:
> > Hi Team,
> >
> > How to understand Regular Expression in a easy way?
> >
> > Thanks,
> > Frank
>
> [1] Learning Perl, Sixth Edition by Randal L. Schwartz, brian d foy, and
> Tom Phoenix
>
> [2] http://onyxneon.com/books/modern_perl/
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>


Re: Regular Expression Help.

2015-03-25 Thread Shawn H Corey
On Wed, 25 Mar 2015 10:31:40 +0530
Frank Vino  wrote:

> Hi Team,
> 
> How to understand Regular Expression in a easy way?
> 
> Thanks,
> Frank

Sorry Frank but there's no easy way. ☹

Some things to remember:

Some punctuation marks have special meaning, like periods, question
marks, and asterisks. But if there is a backslash before them, then
they match themselves. This is true for all punctuation marks.

And the opposite is true for ASCII letters and numbers. A backslash
before them may give them special meaning but if there is none, then
they match themselves.


-- 
Don't stop where the ink does.
Shawn

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




Re: Regular Expression Help.

2015-03-25 Thread Simon Reinhardt
Hi Frank,

when first learning regexps I read the section "In the World of Regular
Expressions" in the Lama-Book [1]. If you find this introduction to
slow, you might also take a look at chromatic's Modern Perl, which is
available for free [2].

Regards, Simon

Am 25.03.2015 um 06:01 schrieb Frank Vino:
> Hi Team,
> 
> How to understand Regular Expression in a easy way?
> 
> Thanks,
> Frank

[1] Learning Perl, Sixth Edition by Randal L. Schwartz, brian d foy, and
Tom Phoenix

[2] http://onyxneon.com/books/modern_perl/

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




Re: Regular Expression Help.

2015-03-24 Thread Shlomi Fish
Hi Frank,

On Wed, 25 Mar 2015 10:31:40 +0530
Frank Vino  wrote:

> Hi Team,
> 
> How to understand Regular Expression in a easy way?
> 

This page has links to some recommended tutorials about learning regular
expressions:

http://perl-begin.org/topics/regular-expressions/

*NOTE*: I originated perl-begin.org and still maintain it, but everyone is
welcome to contribute to it.

Regards,

Shlomi Fish

-- 
-
Shlomi Fish   http://www.shlomifish.org/
List of Text Processing Tools - http://shlom.in/text-proc

When it comes to terminators, you have a better shot at Arnold Schwarzenegger
than at Summer Glau.  (Via The Big Bang Theory)
— http://www.shlomifish.org/humour/bits/facts/Summer-Glau/

Please reply to list if it's a mailing list post - http://shlom.in/reply .

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




Re: Regular Expression Help.

2015-03-24 Thread Rahul Gojame
Frank,

Just go through below site, it helps to build regex and test same easily.
http://www.regexr.com/

~Rahul

On Wed, Mar 25, 2015 at 10:42 AM, Akshay Mohit 
wrote:

> Just start using it and you will find it very easy to understand.
>
> -Akshay
>
> On Wed, Mar 25, 2015 at 10:31 AM, Frank Vino  wrote:
>
>> Hi Team,
>>
>> How to understand Regular Expression in a easy way?
>>
>> Thanks,
>> Frank
>>
>
>


Re: Regular Expression Help.

2015-03-24 Thread Akshay Mohit
Just start using it and you will find it very easy to understand.

-Akshay

On Wed, Mar 25, 2015 at 10:31 AM, Frank Vino  wrote:

> Hi Team,
>
> How to understand Regular Expression in a easy way?
>
> Thanks,
> Frank
>


Re: Regular expression help pls !

2013-08-23 Thread jet speed
Chaps,
I am testing all your code one by one, Appreciate your time and detailed
inputs.

Many Thanks
Sj




On Fri, Aug 23, 2013 at 6:01 PM, Jim Gibson  wrote:

>
> On Aug 23, 2013, at 9:06 AM, jet speed wrote:
>
> > Chaps,
> >
> > Please i need help on the regular expression, i have the sample code
> below.
> > I only want to match the entries from the array to the file and print
> the matching line
> >
> > for example if i only want to match fc3/23, in my code it prints both
> the lines fc3/2 and fc3/23. How to restrict to exact matches and print only
> ex: fc3/23
> >
> >
> >
> > out.txt
> > --
> >
> > fc3/2  10:00:00:00  host1
> > fc3/23 10:00:00:00  host2
> > fc10/1 10:00:00:00  host3
> > fc10/11 10:00:00:00  host4
> > fc3/1 10:00:00:00  host5
> > fc3/14 10:00:00:00  host6
> > fc12/1 10:00:00:00  host7
> > fc12/1210:00:00:00  host8
> >
> >
> > sample code
> > -
>
> The code below does not compile. Please make sure you post valid programs
> if you want help.
>
> >
> > my @check = (fc3/23, fc10/1, fc3/14, fc12/12);
>
> You need to put quotes around strings:
>
> my @check = ('fc3/23', 'fc10/1', 'fc3/14', 'fc12/12');
>
>
> > my $f2 = 'out.txt';
> > for my $element(@check) {
>
> You should indent blocks (for, while) for readability.
>
>
> > open my $fh2, '<', $f2 or die "could not open $f2: $!";
>
> Here, you are opening the file for each iteration. Reading files is much
> slower than iterating over an array. Therefore, if you have to 1) read a
> file and 2) iterate over an array, you should reverse the order of
> operations: Read a line from the file and then iterate over the array for
> each line in the file.
>
> > while (my $line = <$fh2>) {
> > chomp $line;
> > if ($line = / ^(fc\d+\/\d+/) {
>
> This line has three syntax errors:
> 1. You want the binding operator =~ instead of assignment =
> 2. You don't want a space between / and ^
> 3. The final / and closing ) should be swapped.
>
> I am assuming you mean:
>
>   if ($line =~ /^(fc\d+\/\d+)/ {
>
>
> > $match=$&;
>
> Since your regular expression captures the entire match, you should use
> the capturing variable $1 instead of the whatever-matched variable $&. It
> is actually faster.
>
> Every line of your input will match the above regular expression, so the
> only effect is to extract the first field. You can do that by splitting the
> line on whitespace:
>
>   my( $first, @rest ) = split(/ /,$line);
>
> > }
> > if  ($element =~ $match) {
>
> You need slashes or the m operator to define a regular expression:
>
>   if( $element =~ /$match/ ) {
>
> If you want to match the entire string, you need to add beginning and
> ending anchors:
>
>   if( $element =~ /^$match$/ ) {
>
> But if that is what you want, just use eq:
>
>   if( $element eq $match ) {
>
>
> > print "$line \n";
> > }
> > }
> > }
> >
> >
> > required output
> > 
> >
> > fc3/23 10:00:0:00  host2
> > fc10/1 10:00:0:00  host3
> > fc3/14 10:00:00:00  host6
> > fc12/1210:00:00:00  host8
> >
> > Thanks
> > Sj
> >
>
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>


Re: Regular expression help pls !

2013-08-23 Thread Jim Gibson

On Aug 23, 2013, at 9:06 AM, jet speed wrote:

> Chaps,
> 
> Please i need help on the regular expression, i have the sample code below.
> I only want to match the entries from the array to the file and print the 
> matching line
> 
> for example if i only want to match fc3/23, in my code it prints both the 
> lines fc3/2 and fc3/23. How to restrict to exact matches and print only ex: 
> fc3/23
> 
> 
> 
> out.txt 
> --
> 
> fc3/2  10:00:00:00  host1
> fc3/23 10:00:00:00  host2
> fc10/1 10:00:00:00  host3
> fc10/11 10:00:00:00  host4
> fc3/1 10:00:00:00  host5
> fc3/14 10:00:00:00  host6
> fc12/1 10:00:00:00  host7
> fc12/1210:00:00:00  host8
> 
> 
> sample code 
> -

The code below does not compile. Please make sure you post valid programs if 
you want help.

> 
> my @check = (fc3/23, fc10/1, fc3/14, fc12/12);

You need to put quotes around strings:

my @check = ('fc3/23', 'fc10/1', 'fc3/14', 'fc12/12');


> my $f2 = 'out.txt';
> for my $element(@check) {

You should indent blocks (for, while) for readability.


> open my $fh2, '<', $f2 or die "could not open $f2: $!";

Here, you are opening the file for each iteration. Reading files is much slower 
than iterating over an array. Therefore, if you have to 1) read a file and 2) 
iterate over an array, you should reverse the order of operations: Read a line 
from the file and then iterate over the array for each line in the file.

> while (my $line = <$fh2>) {
> chomp $line;
> if ($line = / ^(fc\d+\/\d+/) {

This line has three syntax errors:
1. You want the binding operator =~ instead of assignment =
2. You don't want a space between / and ^
3. The final / and closing ) should be swapped.

I am assuming you mean:

  if ($line =~ /^(fc\d+\/\d+)/ {


> $match=$&;

Since your regular expression captures the entire match, you should use the 
capturing variable $1 instead of the whatever-matched variable $&. It is 
actually faster.

Every line of your input will match the above regular expression, so the only 
effect is to extract the first field. You can do that by splitting the line on 
whitespace:

  my( $first, @rest ) = split(/ /,$line);

> }
> if  ($element =~ $match) {

You need slashes or the m operator to define a regular expression:

  if( $element =~ /$match/ ) {

If you want to match the entire string, you need to add beginning and ending 
anchors:

  if( $element =~ /^$match$/ ) {

But if that is what you want, just use eq:

  if( $element eq $match ) {


> print "$line \n";
> }
> }
> }
> 
> 
> required output
> 
> 
> fc3/23 10:00:0:00  host2
> fc10/1 10:00:0:00  host3
> fc3/14 10:00:00:00  host6
> fc12/1210:00:00:00  host8
> 
> Thanks
> Sj
> 


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




Re: Regular expression help pls !

2013-08-23 Thread Nathan Hilterbrand

See sample code below


> Chaps,
>
> Please i need help on the regular expression, i have the sample code
> below.
> I only want to match the entries from the array to the file and print
> the
> matching line
>
> for example if i only want to match fc3/23, in my code it prints both
> the
> lines fc3/2 and fc3/23. How to restrict to exact matches and print
> only ex:
> fc3/23
>
>
>
> out.txt
> --
>
> fc3/2  10:00:00:00  host1
> fc3/23 10:00:00:00  host2
> fc10/1 10:00:00:00  host3
> fc10/11 10:00:00:00  host4
> fc3/1 10:00:00:00  host5
> fc3/14 10:00:00:00  host6
> fc12/1 10:00:00:00  host7
> fc12/1210:00:00:00  host8
>
>
> sample code
> -
>
> my @check = (fc3/23, fc10/1, fc3/14, fc12/12);
>
> my $f2 = 'out.txt';
> for my $element(@check) {
> open my $fh2, '<', $f2 or die "could not open $f2: $!";
> while (my $line = <$fh2>) {
> chomp $line;
> if ($line = / ^(fc\d+\/\d+/) {
> $match=$&;
> }
> if  ($element =~ $match) {
> print "$line \n";
> }
> }
> }
>
>
> required output
> 
>
> fc3/23 10:00:0:00  host2
> fc10/1 10:00:0:00  host3
> fc3/14 10:00:00:00  host6
> fc12/1210:00:00:00  host8
>
> Thanks
> Sj
>

This worked for me:

#!/usr/bin/perl

  use strict;  # Always a good idea!
  use warnings;# likewise!

  # You need quotes around your literals in the line that creates
  # and assigns @check:
  my @check = ("fc3/23", "fc10/1", "fc3/14", "fc12/12");
  my $f2 = 'out.txt';

  # The following lines create a reqexp variable that will match any
  # of the strings in @check.  Note in the map that I placed a space
  # after "$_".  This takes care of the problem where "fc3/2" matched
  # "fc3/23".  When this is done, for this sample, the generated regular
  # expression looks like:
  #(?:fc3/23 )|(?:fc10/1 )|(?:fc3/14 )|(?:fc12/12 )
  # This attempts to match against all of the strings that were in
@check.
  # The use of "(?:" instead of "(" to start each group will make the
  # parenthesis "non-capturing", which is a bit quicker when you don't
need
  # to capture the actual matches.
  #

  my @tmpcheck = map {"(?:$_ )"} @check;
  my $regexp_str = join "|", @tmpcheck;
  my $regexp = qr/$regexp_str/;

  open my $fh2, '<', $f2 or die "could not open $f2: $!";

  while (my $line = <$fh2>) {
print "$line" if $line =~ $regexp;# Print only lines that match
  }

  # Note that I did not chomp the newline and put it back on when
printing.
  # The presence of the newline does not effect the match in this
case, so
  # that was not necessary.

Best of luck.

Nathan
-- 



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




Re: Regular expression help pls !

2013-08-23 Thread David Precious
On Fri, 23 Aug 2013 17:06:41 +0100
jet speed  wrote:

> Chaps,
> 
> Please i need help on the regular expression, i have the sample code
> below. I only want to match the entries from the array to the file
> and print the matching line
> 
> for example if i only want to match fc3/23, in my code it prints both
> the lines fc3/2 and fc3/23. How to restrict to exact matches and
> print only ex: fc3/23

[...]
> if ($line = / ^(fc\d+\/\d+/) {

First off, you mean =~ to match against a regex - that's a fairly
meaningless assignment there.  Was that a typo or is that how it
actually is in your code?

Secondly, that regex shouldn't even compile - you've missed a closing
parenthesis.

Perl should have told you something like:

  Unmatched ( in regex; marked by  

You meant:

if ($line =~ /^(fc\d+\/\d+)/) {

Although I would write that a little more clearly - using qr lets you
pick delimiters that avoid you having to escape the slash in the
middle, and using the "x" modifier makes the regex whitespace
insensitive, so you can space things out for readability - and also,
assign the match to a meaningful var immediately:

if (my ($port) = $line =~ qr{^ (fc \d+ / \d+ ) }x) {
# matched, $port contains e.g. fc3/23
}


Also, iterating through the file once for each port you want to look
for is a rather inefficient approach - reverse the logic, and loop
through each line in the file, checking it against each of your ports
of interest within the loop - for example:

open my $fh, '<', $filename or die "Failed to open $filename - $!";
while (my $line = <$fh>) {
chomp $line;
if (my ($port) = $line =~ qr{^ (fc \d+ / \d+ ) }x) {
if (grep { $port eq $_ } @check) {
# $port matched one of the ones you wanted.
print "$line\n";
}
}
}


Hope that helps?


-- 
David Precious ("bigpresh") 
http://www.preshweb.co.uk/ www.preshweb.co.uk/twitter
www.preshweb.co.uk/linkedinwww.preshweb.co.uk/facebook
www.preshweb.co.uk/cpanwww.preshweb.co.uk/github



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




Re: Regular expression help pls !

2013-08-23 Thread Shawn H Corey
On Fri, 23 Aug 2013 17:06:41 +0100
jet speed  wrote:

> my @check = (fc3/23, fc10/1, fc3/14, fc12/12);

my @check = qw( fc3/23 fc10/1 fc3/14 fc12/12 );

> 
> my $f2 = 'out.txt';
> for my $element(@check) {
> open my $fh2, '<', $f2 or die "could not open $f2: $!";
> while (my $line = <$fh2>) {
> chomp $line;

# put the for loop inside the while
open my $fh2, '<', $f2 or die "could not open $f2: $!";
while (my $line = <$fh2>) {
chomp $line;
for my $element(@check) {
if( $line =~ /^\Q$element\E\s/ ){
print "$line \n";
last;
}
}
}



-- 
Don't stop where the ink does.
Shawn

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




Re: Regular expression help pls !

2013-08-23 Thread Gianrossi, Paolo
Not sure I get it, but would

/^fc3\/2\b/ 

(assuming you're looking for fc3/2 and not fc3/23) work?

hth
paolino

On 23 Aug 2013, at 17:06, jet speed  wrote:

> Chaps,
> 
> Please i need help on the regular expression, i have the sample code below.
> I only want to match the entries from the array to the file and print the 
> matching line
> 
> for example if i only want to match fc3/23, in my code it prints both the 
> lines fc3/2 and fc3/23. How to restrict to exact matches and print only ex: 
> fc3/23
> 
> 
> 
> out.txt 
> --
> 
> fc3/2  10:00:00:00  host1
> fc3/23 10:00:00:00  host2
> fc10/1 10:00:00:00  host3
> fc10/11 10:00:00:00  host4
> fc3/1 10:00:00:00  host5
> fc3/14 10:00:00:00  host6
> fc12/1 10:00:00:00  host7
> fc12/1210:00:00:00  host8
> 
> 
> sample code 
> -
> 
> my @check = (fc3/23, fc10/1, fc3/14, fc12/12);
> 
> my $f2 = 'out.txt';
> for my $element(@check) {
> open my $fh2, '<', $f2 or die "could not open $f2: $!";
> while (my $line = <$fh2>) {
> chomp $line;
> if ($line = / ^(fc\d+\/\d+/) {
> $match=$&;
> }
> if  ($element =~ $match) {
> print "$line \n";
> }
> }
> }
> 
> 
> required output
> 
> 
> fc3/23 10:00:0:00  host2
> fc10/1 10:00:0:00  host3
> fc3/14 10:00:00:00  host6
> fc12/1210:00:00:00  host8
> 
> Thanks
> Sj
> 


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




Re: regular expression help

2012-09-21 Thread Octavian Rasnita

From: "Dr.Ruud" 


On 2012-09-20 09:08, Octavian Rasnita wrote:


my ( $file_name ) = $data =~ /([^\\]+)$/g;


No need for that g-modifier.

--
Ruud




Yes, you are right. I added it by mistake.

Octavian


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




Re: regular expression help

2012-09-20 Thread Dr.Ruud

On 2012-09-20 09:08, Octavian Rasnita wrote:


my ( $file_name ) = $data =~ /([^\\]+)$/g;


No need for that g-modifier.

--
Ruud



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




Re: regular expression help

2012-09-20 Thread Irfan Sayed
thanks a lot for all the responses :)

regards





 From: Shlomi Fish 
To: Michael Brader  
Cc: beginners@perl.org 
Sent: Thursday, September 20, 2012 2:53 PM
Subject: Re: regular expression help
 
On Thu, 20 Sep 2012 17:13:07 +0930
Michael Brader  wrote:

> A more idiomatic way to do this is to use the File::Spec module.
> Inspect the output of this program for inspiration:
> 

There's also File::Basename:

http://perldoc.perl.org/File/Basename.html

Regards,

    Shlomi Fish

-- 
-
Shlomi Fish       http://www.shlomifish.org/
Optimising Code for Speed - http://shlom.in/optimise

Chuck Norris was never a newbie! He will kill anyone who implies otherwise. In
a very not newbie-like manner.

Please reply to list if it's a mailing list post - http://shlom.in/reply .

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

Re: regular expression help

2012-09-20 Thread Shlomi Fish
On Thu, 20 Sep 2012 17:13:07 +0930
Michael Brader  wrote:

> A more idiomatic way to do this is to use the File::Spec module.
> Inspect the output of this program for inspiration:
> 

There's also File::Basename:

http://perldoc.perl.org/File/Basename.html

Regards,

Shlomi Fish

-- 
-
Shlomi Fish   http://www.shlomifish.org/
Optimising Code for Speed - http://shlom.in/optimise

Chuck Norris was never a newbie! He will kill anyone who implies otherwise. In
a very not newbie-like manner.

Please reply to list if it's a mailing list post - http://shlom.in/reply .

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




Re: regular expression help

2012-09-20 Thread Michael Brader


On 09/20/2012 04:39 PM, Irfan Sayed wrote:

got it myself :)
thanks a lot
  $line_to_add =~ m/([a-zA-Z]+\.csproj)/;



Hi Irfan,

Your solution will only match files that consist of ASCII alphabetic 
characters followed by '.csproj'. It will also match these:


* 'c:\p4\car\abc\foo.csproj\file.txt'
* 'c:\p4\car\abc\123xyx.csproj'
* 'c:\p4\car\abc\xyz.csprojabc'

Octavian's solution is much more general. Run this program to see why:

#!/usr/bin/perl

use strict;
use warnings;

my @paths = (
'c:\p4\car\abc\xyz.csproj',
'c:\p4\car\abc\foo.csproj\file.txt',
'c:\p4\car\abc\123xyx.csproj',
'c:\p4\car\abc\xyz.csprojabc',
);

foreach my $path ( @paths ) {
my ($irfan) = $path =~ m/([a-zA-Z]+\.csproj)/;
$irfan ||= 'no match';
my ($octavian) = $path =~ /([^\\]+)$/;
$octavian ||= 'no match';
print <<"EOINFO";
Path: $path
Irfan: $irfan
Octavian: $octavian

EOINFO
}
__END__

Path: c:\p4\car\abc\xyz.csproj
Irfan: xyz.csproj
Octavian: xyz.csproj

Path: c:\p4\car\abc\foo.csproj\file.txt
Irfan: foo.csproj
Octavian: file.txt

Path: c:\p4\car\abc\123xyx.csproj
Irfan: xyx.csproj
Octavian: 123xyx.csproj

Path: c:\p4\car\abc\xyz.csprojabc
Irfan: xyz.csproj
Octavian: xyz.csprojabc

A more idiomatic way to do this is to use the File::Spec module. Inspect 
the output of this program for inspiration:


#!/usr/bin/perl

use strict;
use warnings;

use File::Spec; # for splitpath

my $path = 'c:\p4\car\abc\xyz.csproj';

my ( $volume, $directories, $file) = File::Spec->splitpath( $path );

print <<"EOINFO";
Volume: $volume
Directories: $directories
File: $file
EOINFO

exit 0;
__END__

Cheers,
Michael


--
Michael BraderSenior Software Engineer and Perl Person
  Technology/Softdev/M&E Small Change Team
Internode   http://internode.on.net/  mbra...@internode.com.au
iiNet http://iinet.net.au/ m.bra...@staff.iinet.net.au


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




Re: regular expression help

2012-09-20 Thread Irfan Sayed
got it myself :)
thanks a lot 
 $line_to_add =~ m/([a-zA-Z]+\.csproj)/;

regards




 From: Irfan Sayed 
To: Perl Beginners  
Sent: Thursday, September 20, 2012 12:07 PM
Subject: regular expression help 
 
i have string 'c:\p4\car\abc\xyz.csproj'

i just need to match the xyz.csproj

i tried few option but does not help. 

can someone please suggest

regards
irfan

Re: regular expression help

2012-09-20 Thread Octavian Rasnita

From: "Irfan Sayed" 

i have string 'c:\p4\car\abc\xyz.csproj'

i just need to match the xyz.csproj

i tried few option but does not help.

can someone please suggest

regards
irfan




my $data = 'c:\p4\car\abc\xyz.csproj';

my ( $file_name ) = $data =~ /([^\\]+)$/g;

print $file_name;

It will print:
xyz.csproj

( and ) captures the matched string but because in this case they capture 
the whole regular expression, you can omit using them like:


my ( $file_name ) = $data =~ /[^\\]+$/g;

[^\\] means that it matches everything which is not a \ char, and because \ 
is a special char, it should be escaped with another \ before it (this is 
why there are 2 \ chars).


There is a + char after the [^\\] meaning that [^\\] doesn't match just a 
single char, but one or more.


And at the end there is a $ sign meaning that after this string that mached, 
it is the end of the string, so this regex will match any substring which 
doesn't contain a \ char which appear at the end of the string.


HTH, and of course, use strict and warnings.

Octavian



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




Re: Regular Expression help!

2011-05-11 Thread jet speed
Hi All,

Thanks for your time and valuable inputs, Appreciate it.

I will try your suggestions and test it in my program.

Sj


Re: Regular Expression help!

2011-05-11 Thread C.DeRykus
On May 11, 8:38 am, speedj...@googlemail.com (jet speed) wrote:
> Hi All,
>
> I need help in matching the regular expression, the file is as below.
>
> I am trying to match number followed by Number ex 587, 128 in $1 and
> 60:06:01:60:42:40:21:00:3A:AA:55:37:91:8A:DF:11 in $2
>
> the $1 match works find with regulare expression  #if ($_=~
> /\w{7}\s\w{4}\s\w{6}\s(\d{1,4})/i) { #workts for 1st line
>
> However i am not sure how to get both $1 and $2 togather.
>
> Ideally i would like to have an output printed
>
> print "$1 wwn is $2 \n";
>
> Any help on this would be much appreciated.
>
> FILE
> ---
>
> LOGICAL UNIT NUMBER 587
> UID:                        60:06:01:60:42:40:21:00:3A:AA:55:37:91:8A:DF:11
>
> LOGICAL UNIT NUMBER 128
> UID:                        60:06:01:60:50:40:21:00:D0:23:D5:C2:BA:D9:DE:11
>
> LOGICAL UNIT NUMBER 763
> UID:                        60:06:01:60:50:40:21:00:25:C6:3F:A7:CA:2D:DF:11
>
> ---
>
> #!/usr/bin/perl
> open(FILE, "clrlist") || die "Can't open clrlist : $!\n";
>
> while () {
> #if ($_=~ /\w{7}\s\w{4}\s\w{6}\s(\d{1,4})/i) { #workts for 1st line
> ...

Also, you may want to consider the /x modifier to avoid
"regex blindness", [a visual Bermuda Triangle that will
cause anyone viewing it to avert their eyes and quickly
paddle the other way].

Even with an easy regex,  the view improves considerably
with /x :

if  (  /  \w{7}  \s \w{4} \s# insert comment here...
  \d{1,4}   # more comments...
  
   /ix  )

Or just:
  / \w{7} \s  \w{4}  \s   /ix;  # whitespace enhanced

--
Charles DeRykus


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




Re: Regular Expression help!

2011-05-11 Thread Rob Dixon
On 11/05/2011 16:38, jet speed wrote:
> Hi All,
> 
> I need help in matching the regular expression, the file is as below.
> 
> I am trying to match number followed by Number ex 587, 128 in $1 and
> 60:06:01:60:42:40:21:00:3A:AA:55:37:91:8A:DF:11 in $2
> 
> the $1 match works find with regulare expression  #if ($_=~ 
> /\w{7}\s\w{4}\s\w{6}\s(\d{1,4})/i) { #workts for 1st line
> 
> However i am not sure how to get both $1 and $2 togather.
> 
> Ideally i would like to have an output printed
> 
> print "$1 wwn is $2 \n";
> 
> Any help on this would be much appreciated.
> 
> 
> FILE
> ---
> 
> 
> LOGICAL UNIT NUMBER 587
> UID:60:06:01:60:42:40:21:00:3A:AA:55:37:91:8A:DF:11
> 
> LOGICAL UNIT NUMBER 128
> UID:60:06:01:60:50:40:21:00:D0:23:D5:C2:BA:D9:DE:11
> 
> LOGICAL UNIT NUMBER 763
> UID:60:06:01:60:50:40:21:00:25:C6:3F:A7:CA:2D:DF:11
> 
> ---
> 
> 
> #!/usr/bin/perl
> open(FILE, "clrlist") || die "Can't open clrlist : $!\n";
> 
> while () {
> #if ($_=~ /\w{7}\s\w{4}\s\w{6}\s(\d{1,4})/i) { #workts for 1st line
> if ($_=~ 
> /\w{7}\s\w{4}\s\w{6}\s(\d{1,4})\n[a-z0-9+]\s*(\d{2}*\d{2}*\d{2}*\d{2}*\d{2}*\d{2}*\d{2}*\d{2}*\d{2}*\d{2}*\d{2}*\d{2}*\d{2}*\d{2}*\d{2}*\d{2}*)/i)
> {
> print "$1 ";
> print "$2";
>  }
> }
> 
> -

I think I understand what you hope to achieve, but your code will not
compile as it stands.

First of all, instead of

  /\w{7}\s\w{4}\s\w{6}\s(\d{1,4})/i

you should write simply

  /LOGICAL UNIT NUMBER (\d{1,4})/i

Your second regex is similar, but anything like

  /\d{2}*/

gives the error 'Nested quantifiers in regex'. You can specify either
{2} (exactly two occurrences) or * (zero or more occurrences) but not both!

Also, you are trying to match a string of 16 hex bytes using /\d/. That
matches only 0..9 in ASCII (and a lot more in Unicode, but that isn't a
problem here). For hex, use either /[0-9A-X]/i or /[[:xdigit:]]/.

But the main problem is that you are trying to match two lines
simultaneously. Your regex contains /\n/, but you are reading from the
file only one line at a time. Each line will contain *either*

  "LOGICAL UNIT NUMBER 587\n"

*or*

  "UID:
60:06:01:60:50:40:21:00:25:C6:3F:A7:CA:2D:DF:11\n"

so you need to code accordingly.

On top of that, your second regex includes /[a-z0-9+]/i when I think you
meant /[a-z0-9]+/i, and it doesn't allow for the colon after 'UID'. Once
more, this should be /UID:\s*/ or something similar. Without seeing your
data I cannot help further.

For those who would help, I believe the program looks as below.

I hope this helps,

Rob



use strict;
use warnings;

while () {

  #if ($_=~ /\w{7}\s\w{4}\s\w{6}\s(\d{1,4})/i) { #workts for 1st line

  if ($_=~ 
/\w{7}\s\w{4}\s\w{6}\s(\d{1,4})\n[a-z0-9+]\s*(\d{2}*\d{2}*\d{2}*\d{2}*\d{2}*\d{2}*\d{2}*\d{2}*\d{2}*\d{2}*\d{2}*\d{2}*\d{2}*\d{2}*\d{2}*\d{2}*)/i)
 {
print "$1 ";
print "$2";
  }
}

__DATA__
LOGICAL UNIT NUMBER 587
UID:60:06:01:60:42:40:21:00:3A:AA:55:37:91:8A:DF:11

LOGICAL UNIT NUMBER 128
UID:60:06:01:60:50:40:21:00:D0:23:D5:C2:BA:D9:DE:11

LOGICAL UNIT NUMBER 763
UID:60:06:01:60:50:40:21:00:25:C6:3F:A7:CA:2D:DF:11

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




Re: Regular Expression help!

2011-05-11 Thread Shawn H Corey

On 11-05-11 11:38 AM, jet speed wrote:

I need help in matching the regular expression, the file is as below.

I am trying to match number followed by Number ex 587, 128 in $1 and
60:06:01:60:42:40:21:00:3A:AA:55:37:91:8A:DF:11 in $2

the $1 match works find with regulare expression  #if ($_=~
/\w{7}\s\w{4}\s\w{6}\s(\d{1,4})/i) { #workts for 1st line

However i am not sure how to get both $1 and $2 togather.

Ideally i would like to have an output printed

print "$1 wwn is $2 \n";

Any help on this would be much appreciated.


You are trying to do too much in one regular expression.  Process the 
file one line at a time.


#!/usr/bin/env perl

use strict;
use warnings;

my $lun = 0;
while(  ){
  if( /^\s*LOGICAL\s+UNIT\s+NUMBER\s+(\d+)/ ){
$lun = $1;
  }elsif( /^UID:\s*(\S+)/ ){
print "$lun wwn is $1 \n";
  }
}

__DATA__


LOGICAL UNIT NUMBER 587
UID:60:06:01:60:42:40:21:00:3A:AA:55:37:91:8A:DF:11

LOGICAL UNIT NUMBER 128
UID:60:06:01:60:50:40:21:00:D0:23:D5:C2:BA:D9:DE:11

LOGICAL UNIT NUMBER 763
UID:60:06:01:60:50:40:21:00:25:C6:3F:A7:CA:2D:DF:11




--
Just my 0.0002 million dollars worth,
  Shawn

Confusion is the first step of understanding.

Programming is as much about organization and communication
as it is about coding.

The secret to great software:  Fail early & often.

Eliminate software piracy:  use only FLOSS.

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




Re: Regular Expression help!

2011-05-11 Thread Leo Susanto
I ended up confused after reading your email.

Please specify INPUT + OUTPUT/condition.

You have already specify INPUT which is:
LOGICAL UNIT NUMBER 587
UID:60:06:01:60:42:40:21:00:3A:AA:55:37:91:8A:DF:11

LOGICAL UNIT NUMBER 128
UID:60:06:01:60:50:40:21:00:D0:23:D5:C2:BA:D9:DE:11

LOGICAL UNIT NUMBER 763
UID:60:06:01:60:50:40:21:00:25:C6:3F:A7:CA:2D:DF:11

What is the desired OUTPUT/condition?

Is it something like this?
587 wwn is 60:06:01:60:42:40:21:00:3A:AA:55:37:91:8A:DF:11
128 wwn is 60:06:01:60:50:40:21:00:D0:23:D5:C2:BA:D9:DE:11
763 wwn is 60:06:01:60:50:40:21:00:25:C6:3F:A7:CA:2D:DF:11

On Wed, May 11, 2011 at 8:38 AM, jet speed  wrote:
> Hi All,
>
> I need help in matching the regular expression, the file is as below.
>
> I am trying to match number followed by Number ex 587, 128 in $1 and
> 60:06:01:60:42:40:21:00:3A:AA:55:37:91:8A:DF:11 in $2
>
> the $1 match works find with regulare expression  #if ($_=~
> /\w{7}\s\w{4}\s\w{6}\s(\d{1,4})/i) { #workts for 1st line
>
> However i am not sure how to get both $1 and $2 togather.
>
> Ideally i would like to have an output printed
>
> print "$1 wwn is $2 \n";
>
> Any help on this would be much appreciated.
>
>
> FILE
> ---
>
>
> LOGICAL UNIT NUMBER 587
> UID:                        60:06:01:60:42:40:21:00:3A:AA:55:37:91:8A:DF:11
>
> LOGICAL UNIT NUMBER 128
> UID:                        60:06:01:60:50:40:21:00:D0:23:D5:C2:BA:D9:DE:11
>
> LOGICAL UNIT NUMBER 763
> UID:                        60:06:01:60:50:40:21:00:25:C6:3F:A7:CA:2D:DF:11
>
> ---
>
>
> #!/usr/bin/perl
> open(FILE, "clrlist") || die "Can't open clrlist : $!\n";
>
> while () {
> #if ($_=~ /\w{7}\s\w{4}\s\w{6}\s(\d{1,4})/i) { #workts for 1st line
> if ($_=~ 
> /\w{7}\s\w{4}\s\w{6}\s(\d{1,4})\n[a-z0-9+]\s*(\d{2}*\d{2}*\d{2}*\d{2}*\d{2}*\d{2}*\d{2}*\d{2}*\d{2}*\d{2}*\d{2}*\d{2}*\d{2}*\d{2}*\d{2}*\d{2}*)/i)
> {
> print "$1 ";
> print "$2";
>        }
> }
>
> -
>
> Sj
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>

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




Re: Regular expression help !!

2011-04-27 Thread jet speed
Excellent Guys, I would like thank each one of you for inputs. Much
appreciated.

i got blinded by just the numbers 0079, i didn't cater for the next line
which is hex 007A, as one of you rightly pointed out [ 0-9A-Z] , does the
trick.  its amazing to see different technique to achieve the same result.
Thanks again.

Sj


Re: Regular expression help !!

2011-04-27 Thread Dr.Ruud

On 2011-04-27 18:47, Jim Gibson wrote:


The metasymbol \d matches the characters [0-9],


Beware: the \d matches 250+ code points. So don't use \d if you only 
mean [0-9].




not the extended hexadecimal
set that includes A-Z. To match those, construct your own character class:

[0-9A-Z]


Or use [[:xdigit:]], though that also matches the lowercase a-f.

(I assume that you meant A-F)

--
Ruud

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




Re: Regular expression help !!

2011-04-27 Thread Brian Fraser
On Wed, Apr 27, 2011 at 2:48 PM, Shawn H Corey  wrote:

> On 11-04-27 12:47 PM, Jim Gibson wrote:
>
>> The metasymbol \d matches the characters [0-9], not the extended
>> hexadecimal
>> set that includes A-Z. To match those, construct your own character class:
>>
>> [0-9A-Z]
>>
>
> You can use the POSIX xdigit character class instead:

Or the Unicode character propriety[0] \p{Hex} (or \p{Hex_Digit} or whichever
form you prefer the most).

Or, since the data seems to always come in the same form, instead of using a
regex, you could pull out unpack [1]:
use 5.010;

while () {
say join ',', (unpack "A5 A24 A*")[0,-1];
}

You can learn more about pack/unpack in perlpacktut[2]

Or you could use substr[3]:
while () {
chomp;
say join ',', substr($_, 0, 4), substr($_, 29);
}

Brian.

[0] http://perldoc.perl.org/perluniprops.html
[1] http://perldoc.perl.org/functions/unpack.html
[2] http://perldoc.perl.org/perlpacktut.html
[3] http://perldoc.perl.org/functions/substr.html


Re: Regular expression help !!

2011-04-27 Thread Shawn H Corey

On 11-04-27 12:47 PM, Jim Gibson wrote:

The metasymbol \d matches the characters [0-9], not the extended hexadecimal
set that includes A-Z. To match those, construct your own character class:

[0-9A-Z]


You can use the POSIX xdigit character class instead:

#!/usr/bin/env perl

use strict;
use warnings;

use Data::Dumper;

# Make Data::Dumper pretty
$Data::Dumper::Sortkeys = 1;
$Data::Dumper::Indent   = 1;

# Set maximum depth for Data::Dumper, zero means unlimited
local $Data::Dumper::Maxdepth = 0;

while(  ){
  my @hex_numbers = ( m{ ( [[:xdigit:]]+ ) }gmsx )[ 0, -1 ];
  print '@hex_numbers: ', Dumper \@hex_numbers;
}

__DATA__
0079 Not Visible 69729260057253303030373
007A Not Visible 69729260057253303030374
007B Not Visible 69729260057253303030374
007C Not Visible 69729260057253303030374
007D Not Visible 69729260057253303030374
007E Not Visible 69729260057253303030374


See `perldoc perlreref` and search for /xdigit/


--
Just my 0.0002 million dollars worth,
  Shawn

Confusion is the first step of understanding.

Programming is as much about organization and communication
as it is about coding.

The secret to great software:  Fail early & often.

Eliminate software piracy:  use only FLOSS.

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




Re: Regular expression help !!

2011-04-27 Thread Paul Johnson
On Wed, Apr 27, 2011 at 04:32:57PM +0100, jet speed wrote:
> Hi all,
> 
> Thanks for all our inputs,
> 
> The regular expression below works fine if do it for single line, i am
> trying to caputre the match $1, and $2 into array. only the first line
> is pushed to the array. what am i doing wrong ?
> how to get all the $1 and $2 match values for each line into arrary ?
> Kindly advice.
> 
> 
> # more wwnlist
> 0079 Not Visible 69729260057253303030373
> 007A Not Visible 69729260057253303030374
> 007B Not Visible 69729260057253303030374
> 007C Not Visible 69729260057253303030374
> 007D Not Visible 69729260057253303030374
> 007E Not Visible 69729260057253303030374

> if ($_=~/\b(\d{4})\s[a-z]{1,3}\s[a-z]{1,7}\s*(\d{1,32})\b/i) {

\d doesn't match hex digits or, at least not all of them.

Instead of your first \d you could use [0-9A-F] which actually matches exactly
the characters you want.  \d will also match many characters you probably
don't want to match, unfortunately.

However, I might be tempted to go with Rob's second solution, unless you are
sure each line matches that regexp exactly.  And if you are, is it always "Not
Visible" in there, or can it really be any three and seven letter words?  If
not, why not use "Not Visible" in your regexp?

-- 
Paul Johnson - p...@pjcj.net
http://www.pjcj.net

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




Re: Regular expression help !!

2011-04-27 Thread Jim Gibson
On 4/27/11 Wed  Apr 27, 2011  8:32 AM, "jet speed"
 scribbled:

> Hi all,
> 
> Thanks for all our inputs,
> 
> The regular expression below works fine if do it for single line, i am
> trying to caputre the match $1, and $2 into array. only the first line
> is pushed to the array. what am i doing wrong ?
> how to get all the $1 and $2 match values for each line into arrary ?
> Kindly advice.
> 
> 
> # more wwnlist
> 0079 Not Visible 69729260057253303030373
> 007A Not Visible 69729260057253303030374
> 007B Not Visible 69729260057253303030374
> 007C Not Visible 69729260057253303030374
> 007D Not Visible 69729260057253303030374
> 007E Not Visible 69729260057253303030374
>  more wwnmod.pl
> #!/usr/bin/perl
> 
> #0079 Not Visible 69729260057253303030373
> 
> 
> open(FILE, "wwnlist") || die "Can't open wwnlist : $!\n";
> while () {
> if ($_=~/\b(\d{4})\s[a-z]{1,3}\s[a-z]{1,7}\s*(\d{1,32})\b/i) {
> push (@dev, $1);
> push (@wwn, $2);
> }
> }
> 
> print "@dev \n";
> print "@wwn \n";
> 
> ./wwnmod.pl
> 0079
> 69729260057253303030373
[
The metasymbol \d matches the characters [0-9], not the extended hexadecimal
set that includes A-Z. To match those, construct your own character class:

[0-9A-Z]

So your regular expression test will become:

if ($_=~/\b([0-9A-Z]{4})\s[a-z]{1,3}\s[a-z]{1,7}\s*(\d{1,32})\b/i) {




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




Re: Regular expression help !!

2011-04-27 Thread jet speed
Hi all,

Thanks for all our inputs,

The regular expression below works fine if do it for single line, i am
trying to caputre the match $1, and $2 into array. only the first line
is pushed to the array. what am i doing wrong ?
how to get all the $1 and $2 match values for each line into arrary ?
Kindly advice.


# more wwnlist
0079 Not Visible 69729260057253303030373
007A Not Visible 69729260057253303030374
007B Not Visible 69729260057253303030374
007C Not Visible 69729260057253303030374
007D Not Visible 69729260057253303030374
007E Not Visible 69729260057253303030374
 more wwnmod.pl
#!/usr/bin/perl

#0079 Not Visible 69729260057253303030373


open(FILE, "wwnlist") || die "Can't open wwnlist : $!\n";
while () {
if ($_=~/\b(\d{4})\s[a-z]{1,3}\s[a-z]{1,7}\s*(\d{1,32})\b/i) {
push (@dev, $1);
push (@wwn, $2);
}
}

print "@dev \n";
print "@wwn \n";

./wwnmod.pl
0079
69729260057253303030373

Regards

Sj


On 4/27/11, Rob Dixon  wrote:
> On 27/04/2011 11:47, jet speed wrote:
>>
>> Please could you advice, how can i write a regular expression for the
>> line below to capture 0079 and 69729260057253303030373
>>
>>
>> 0079 Not Visible 69729260057253303030373
>>
>> i tried this one, no luck
>>
>> /(^\d{4})\s\w+\s\w+\s+\d+/ig)
>
> It works fine! You are simply not capturing the second sequence of
> digits. This
>
> use strict;
> use warnings;
>
> for ('0079 Not Visible 69729260057253303030373') {
>print /(^\d{4})\s\w+\s\w+\s+(\d+)/ig ? "$1 $2" : 'no match';
> }
>
> prints '0079 69729260057253303030373'.
>
> But, depending on your data, there may be no need to match the line so
> precisely. This does the same thing
>
> use strict;
> use warnings;
>
> for ('0079 Not Visible 69729260057253303030373') {
>my @n = (split)[0,-1];
>print "@n";
> }
>
>
> HTH,
>
> Rob
>

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




Re: Regular expression help !!

2011-04-27 Thread Rob Dixon

On 27/04/2011 11:47, jet speed wrote:


Please could you advice, how can i write a regular expression for the
line below to capture 0079 and 69729260057253303030373


0079 Not Visible 69729260057253303030373

i tried this one, no luck

/(^\d{4})\s\w+\s\w+\s+\d+/ig)


It works fine! You are simply not capturing the second sequence of 
digits. This


use strict;
use warnings;

for ('0079 Not Visible 69729260057253303030373') {
  print /(^\d{4})\s\w+\s\w+\s+(\d+)/ig ? "$1 $2" : 'no match';
}

prints '0079 69729260057253303030373'.

But, depending on your data, there may be no need to match the line so 
precisely. This does the same thing


use strict;
use warnings;

for ('0079 Not Visible 69729260057253303030373') {
  my @n = (split)[0,-1];
  print "@n";
}


HTH,

Rob

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




Re: Regular expression help !!

2011-04-27 Thread Jeff Pang
2011/4/27 jet speed :
> Hi,
>
> Please could you advice, how can i write a regular expression for the
> line below to capture 0079 and 69729260057253303030373
>
>
> 0079 Not Visible             69729260057253303030373
>


This might help?

$ perl -le '
$str="0079 Not Visible 69729260057253303030373";
@re = $str =~ /^(\d+).*?(\d+)$/;
print "@re"'

0079 69729260057253303030373

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




Re: Regular expression help !!

2011-04-27 Thread Shawn H Corey

On 11-04-27 06:47 AM, jet speed wrote:

0079 Not Visible 69729260057253303030373


Try this:

#!/usr/bin/env perl

use strict;
use warnings;

my $text = '0079 Not Visible 69729260057253303030373';

my @numbers = $text =~ /(\d+)/g;
print "@numbers\n";

__END__


--
Just my 0.0002 million dollars worth,
  Shawn

Confusion is the first step of understanding.

Programming is as much about organization and communication
as it is about coding.

The secret to great software:  Fail early & often.

Eliminate software piracy:  use only FLOSS.

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




Re: Regular expression help !!

2011-04-27 Thread Paolo Gianrossi
2011/4/27 jet speed 

> Hi,
>
> Please could you advice, how can i write a regular expression for the
> line below to capture 0079 and 69729260057253303030373
>
>
> 0079 Not Visible 69729260057253303030373
>
> i tried this one, no luck
>
> /(^\d{4})\s\w+\s\w+\s+\d+/ig)
>
>
>
What about
 /^(\d+)\D+(\d+)$/ ?



> Appreciate your help with this.
>
>
Not sure wether this is actually what you need, though


> Sj
>
>
cheers
paolino


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


Re: Regular expression help

2009-08-26 Thread Chas. Owens
On Wed, Aug 26, 2009 at 03:46, Dave Tang wrote:
snip
>> for my $token ($line =~ /([,"]|[^,"]+)/g) {
>
> I changed the single pipe (|) to double pipes (||) and $token also contained
> empty strings. Could you explain the difference between the pipes?
snip

The pipe character in regexes creates an alternation.  An alternation
matches if one of the expressions matches.  By adding another pipe,
you told the regex engine that it should match [,"] or nothing or
[^,"].  The empty strings you saw were the nothings being matched.  I
can only assume you changed it to || out of some mistaken belief that
the pipe character in a regex is an or statement (like the ||
operator).  While it does operator in a similar fashion, it is not an
or operator.

>>        if ($in_string) {
>>                if ($token eq q/"/) {
>>                        $in_string = 0;
>>                        push @rec, "";
>>                        next;
>>                }
>>        } elsif ($token eq q/,/) {
>>                push @rec, "";
>>                next;
>>        } elsif ($token eq q/"/) {
>>                $in_string = 1;
>>                next;
>>        }
>>        $rec[-1] .= $token;
>
> Is this a commonly used method where you push empty values into an array (if
> $token is a , or ") and append stuff to the last array element (which is an
> empty string)?

It is commonly used by me, I don't know about others. The string at
the end of the record array is not necessarily empty.  In the case of
'"foo,bar"', the tokens are ('"', "foo", ",", "bar", '"').  This means
$rec[-1] starts empty (my @rec = ("");), then "foo" is concatenated
onto it, then ",", then "bar", finally it sees the second '"' token
and pushes a new empty string onto the array.  It looks like there is
a bug though.  It should only push a new string onto the array when it
sees a comma.


-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

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




Re: Regular expression help

2009-08-26 Thread Dave Tang
On Wed, 26 Aug 2009 16:41:39 +1000, Chas. Owens   
wrote:



On Wed, Aug 26, 2009 at 02:23, Dave Tang wrote:

Dear list,

I am trying to import entries in a csv file into a relational database,
however there are entries such as:

a,b,c,d,e,"f1,f2","g1,g2" which spoil my split(/,/).

snip

Sounds like a job for [Text::CSV][1].  Of course, you an always write
a quick parser:


I did some searching on cpan as Uri suggested and decided on this module.  
Thank you very much for the code! I have some questions on the code.




#!/usr/bin/perl

use strict;
use warnings;

my $line = q/a,b,c,d,e,"f1,f2","g1,g2"/;

my $in_string;
my @rec = ("");
for my $token ($line =~ /([,"]|[^,"]+)/g) {


I changed the single pipe (|) to double pipes (||) and $token also  
contained empty strings. Could you explain the difference between the  
pipes?



if ($in_string) {
if ($token eq q/"/) {
$in_string = 0;
push @rec, "";
next;
}
} elsif ($token eq q/,/) {
push @rec, "";
next;
} elsif ($token eq q/"/) {
$in_string = 1;
next;
}
$rec[-1] .= $token;


Is this a commonly used method where you push empty values into an array  
(if $token is a , or ") and append stuff to the last array element (which  
is an empty string)?



}

print join("|", @rec), "\n";


[1] : http://search.cpan.org/dist/Text-CSV/lib/Text/CSV.pm



Thanks again Chas.

--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/


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




Re: Regular expression help

2009-08-25 Thread Chas. Owens
On Wed, Aug 26, 2009 at 02:23, Dave Tang wrote:
> Dear list,
>
> I am trying to import entries in a csv file into a relational database,
> however there are entries such as:
>
> a,b,c,d,e,"f1,f2","g1,g2" which spoil my split(/,/).
snip

Sounds like a job for [Text::CSV][1].  Of course, you an always write
a quick parser:

#!/usr/bin/perl

use strict;
use warnings;

my $line = q/a,b,c,d,e,"f1,f2","g1,g2"/;

my $in_string;
my @rec = ("");
for my $token ($line =~ /([,"]|[^,"]+)/g) {
if ($in_string) {
if ($token eq q/"/) {
$in_string = 0;
push @rec, "";
next;
}
} elsif ($token eq q/,/) {
push @rec, "";
next;
} elsif ($token eq q/"/) {
$in_string = 1;
next;
}
$rec[-1] .= $token;
}

print join("|", @rec), "\n";


[1] : http://search.cpan.org/dist/Text-CSV/lib/Text/CSV.pm

-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

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




Re: Regular expression help

2009-08-25 Thread Uri Guttman
> "DT" == Dave Tang  writes:


  DT> a,b,c,d,e,"f1,f2","g1,g2" which spoil my split(/,/).

  DT> Could someone provide some guidance?

use a CSV module. parsing csv files is a pain with regexes (even if
doable). there are very stable and fast csv modules on cpan so get one
and use it.

uri

-- 
Uri Guttman  --  u...@stemsystems.com    http://www.sysarch.com --
-  Perl Code Review , Architecture, Development, Training, Support --
-  Gourmet Hot Cocoa Mix    http://bestfriendscocoa.com -

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




Re: regular expression help

2009-06-17 Thread John W. Krahn

Irfan Sayed wrote:

Hi All,


Hello,


need help on regular expression.
i have string like this

 "ProductName" = "8:EXFO RTU System 1.2.42"
 
now i want regular expression in such a way that it will change the line to :


 "ProductName" = "8:EXFO RTU System 1.2.43"


$ perl -le'
$_ = q["ProductName" = "8:EXFO RTU System 1.2.42"];
print;
s/(\d+)(\D*)$/ $1 + 1 . $2 /e;
print;
'
"ProductName" = "8:EXFO RTU System 1.2.42"
"ProductName" = "8:EXFO RTU System 1.2.43"



John
--
Those people who think they know everything are a great
annoyance to those of us who do.-- Isaac Asimov

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




Re: regular expression help

2009-06-17 Thread Irfan Sayed
it is not just 1.2.43 it may be anything
it may be like 2.3.56 or 2.0.12 and so on...


plz advice





From: Ajay Kumar 
To: Irfan Sayed 
Cc: "beginners@perl.org" 
Sent: Wednesday, June 17, 2009 5:01:41 PM
Subject: RE: regular expression help

Hi Irfan
This code solve your problem

my $p="\"ProductName\" = \"8:EXFO RTU System 1.2.42\"";
my ($val)=$p=~ m/\d+.\d+.(\d+)\"/;
my $inval=$val+1;
$p=~s/$val/$inval/;
print"===$p\n";
thanks
Ajay


-Original Message-
From: Irfan Sayed [mailto:irfan_sayed2...@yahoo.com]
Sent: Wednesday, June 17, 2009 4:10 PM
To: beginners@perl.org
Subject: regular expression help

Hi All,

need help on regular expression.
i have string like this

"ProductName" = "8:EXFO RTU System 1.2.42"

now i want regular expression in such a way that it will change the line to :

"ProductName" = "8:EXFO RTU System 1.2.43"

i tried in the following way.

    $_ =~ s/:(.*)\s(.*)\s(.*)\s\d*.\d*.\d*/:(.*)\s(.*)\s(.*)\s$chver)/;
where $chver is variable which contains value as 1.2.43

it is not giving result as exprected.

plz advice

regards
irf




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


  

RE: regular expression help

2009-06-17 Thread Ajay Kumar
Hi Irfan
This code solve your problem

my $p="\"ProductName\" = \"8:EXFO RTU System 1.2.42\"";
my ($val)=$p=~ m/\d+.\d+.(\d+)\"/;
my $inval=$val+1;
$p=~s/$val/$inval/;
print"===$p\n";
thanks
Ajay


-Original Message-
From: Irfan Sayed [mailto:irfan_sayed2...@yahoo.com]
Sent: Wednesday, June 17, 2009 4:10 PM
To: beginners@perl.org
Subject: regular expression help

Hi All,

need help on regular expression.
i have string like this

 "ProductName" = "8:EXFO RTU System 1.2.42"

now i want regular expression in such a way that it will change the line to :

 "ProductName" = "8:EXFO RTU System 1.2.43"

i tried in the following way.

$_ =~ s/:(.*)\s(.*)\s(.*)\s\d*.\d*.\d*/:(.*)\s(.*)\s(.*)\s$chver)/;
where $chver is variable which contains value as 1.2.43

it is not giving result as exprected.

plz advice

regards
irf




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




Re: Regular Expression Help

2008-04-16 Thread Rob Dixon
Ley, Chung wrote:
> Hi,
> 
>  
> 
> I have a program that will take in a string that will resolve to a path
> where the output is going to store.
> 
>  
> 
> The path can includes "variables" in this format "%%".
> The acceptable variableNames that the program will support are fixed to
> a list such as "Person", "Class", "Dept".  This list may grow in the
> future; but for now it is fixed.
> 
>  
> 
> So, some of the acceptable strings are:
> 
> C:\Windows\%Person%\%Class%
> 
> C:\MyHomeDir\%Dept%\%Person%
> 
> C:\MyHomeDir\%Dept%_%Person%
> 
> and etc...
> 
>  
> 
> I like to develop a validate method to return false when the string in
> between the % pair don't belong to the acceptable list, and was trying
> to do that with an expression.
> 
> - Look for the string that is in between the "%" by the closest pair.
> 
> - The "%" pair must start at the "odd" occurrence and finish on the
> "next even" occurrence...  Don't know how to describe this exactly, but
> I don't want it to pack this up ("InBetween") from this
> (C:\MyHomeDir\%Dept%InBetween%Person) even though it is in between a %
> pair.
> 
> - Then compare the string within the "%" pair to see if it belongs to
> the "acceptable" list or not.
> 
>  
> 
> Is using a regular expression the right approach here?  or I should just
> iterate thru?

If the names are environment variable names, which is implied by your
syntax, then you can substitute the values of those variables as shown
in the program below.

HTH,

Rob


use strict;
use warnings;

my $str = '%windir%\system32';

$str =~ s/%(.*?)%/$ENV{uc $1}/g;

print $str;

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




Re: Regular Expression Help

2008-04-15 Thread John W. Krahn

Ley, Chung wrote:

Hi,


Hello,


I have a program that will take in a string that will resolve to a path
where the output is going to store.

The path can includes "variables" in this format "%%".
The acceptable variableNames that the program will support are fixed to
a list such as "Person", "Class", "Dept".  This list may grow in the
future; but for now it is fixed.


If you know what the "variable" names will be in advance then you could 
use a regular expression like /%(?:Person|Class|Dept)%/.



John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.-- Larry Wall

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




RE: Regular Expression Help

2008-04-15 Thread Ley, Chung
Thank you!

 

This looks much cleaner.

 



From: Jialin Li [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, April 15, 2008 8:56 PM
To: Ley, Chung
Cc: beginners@perl.org
Subject: Re: Regular Expression Help

 


my $input =q(C:\Windows\%Person%\%Class%);

my @vars = $input =~ /%([^%]+)%/g;

local $, = $/;
print @vars;





On Tue, Apr 15, 2008 at 10:20 PM, Ley, Chung <[EMAIL PROTECTED]> wrote:

Hi,



I have a program that will take in a string that will resolve to a path
where the output is going to store.



The path can includes "variables" in this format "%%".
The acceptable variableNames that the program will support are fixed to
a list such as "Person", "Class", "Dept".  This list may grow in the
future; but for now it is fixed.



So, some of the acceptable strings are:

C:\Windows\%Person%\%Class%

C:\MyHomeDir\%Dept%\%Person%

C:\MyHomeDir\%Dept%_%Person%

and etc...



I like to develop a validate method to return false when the string in
between the % pair don't belong to the acceptable list, and was trying
to do that with an expression.

- Look for the string that is in between the "%" by the closest pair.

- The "%" pair must start at the "odd" occurrence and finish on the
"next even" occurrence...  Don't know how to describe this exactly, but
I don't want it to pack this up ("InBetween") from this
(C:\MyHomeDir\%Dept%InBetween%Person) even though it is in between a %
pair.

- Then compare the string within the "%" pair to see if it belongs to
the "acceptable" list or not.



Is using a regular expression the right approach here?  or I should just
iterate thru?



Thanks...



--Chung Ley

 



Re: Regular Expression Help

2008-04-15 Thread Jialin Li
my $input =q(C:\Windows\%Person%\%Class%);

my @vars = $input =~ /%([^%]+)%/g;

local $, = $/;
print @vars;




On Tue, Apr 15, 2008 at 10:20 PM, Ley, Chung <[EMAIL PROTECTED]> wrote:

> Hi,
>
>
>
> I have a program that will take in a string that will resolve to a path
> where the output is going to store.
>
>
>
> The path can includes "variables" in this format "%%".
> The acceptable variableNames that the program will support are fixed to
> a list such as "Person", "Class", "Dept".  This list may grow in the
> future; but for now it is fixed.
>
>
>
> So, some of the acceptable strings are:
>
> C:\Windows\%Person%\%Class%
>
> C:\MyHomeDir\%Dept%\%Person%
>
> C:\MyHomeDir\%Dept%_%Person%
>
> and etc...
>
>
>
> I like to develop a validate method to return false when the string in
> between the % pair don't belong to the acceptable list, and was trying
> to do that with an expression.
>
> - Look for the string that is in between the "%" by the closest pair.
>
> - The "%" pair must start at the "odd" occurrence and finish on the
> "next even" occurrence...  Don't know how to describe this exactly, but
> I don't want it to pack this up ("InBetween") from this
> (C:\MyHomeDir\%Dept%InBetween%Person) even though it is in between a %
> pair.
>
> - Then compare the string within the "%" pair to see if it belongs to
> the "acceptable" list or not.
>
>
>
> Is using a regular expression the right approach here?  or I should just
> iterate thru?
>
>
>
> Thanks...
>
>
>
> --Chung Ley
>
>


Re: Regular Expression Help

2006-11-01 Thread Ashish Srivastava
Thank You John and Anshul for response. It was great help.

Regards, 
Ashish Srivastava 

 



- Original Message 
From: Anshul Saxena <[EMAIL PROTECTED]>
To: John W. Krahn <[EMAIL PROTECTED]>
Cc: Perl Beginners 
Sent: Wednesday, 1 November, 2006 11:01:38 PM
Subject: Re: Regular Expression Help


Ashish ,
you might have the [ in a recurring sequence using [*

On 11/1/06, John W. Krahn <[EMAIL PROTECTED]> wrote:
>
> Ashish Srivastava wrote:
> > I have a string which have multiple placeholder, for example:
> >
> > $str = 'Hello [[Name]], Your login id is  [[Login]] !!!";
> >
> > I want to replace all placeholder with some identifier. In above
> example: identifier are Name and Login.
> > The regular expression for this requirment is pretty staightward:
> >
> > $str =~ s/\[\[([\d\w\-]+)\]\]/$1/g;
> >
> > Now the problem is there could be  Nested Placeholders. For example:
> >
> > $str = 'Error is: id]]-[[message'
> >
> > so in above example if idenfiers are defined as:
> >
> > id = 1001
> > Message = "Crash"
> > 1001-Crash = "System overloaded"
> >
> > so output of my required regular expression for subsitution should be:
> >
> > Error is: System overloaded
>
> $ perl -le'
> my %t = (
> id   => 1001,
> message  => "Crash",
> "1001-Crash" => "System overloaded",
> );
>
> my $str = q/Error is: id]]-[[message/;
>
> print $str;
>
> 1 while $str =~ s/\[\[([\w-]+)]]/$t{$1}/g;
>
> print $str;
> '
> Error is: id]]-[[message
> Error is: System overloaded
>
>
>
>
> John
> --
> Perl isn't a toolbox, but a small machine shop where you can special-order
> certain sorts of tools at low cost and in short order.   -- Larry Wall
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
>
>
>



__
Yahoo! India Answers: Share what you know. Learn something new
http://in.answers.yahoo.com/

Re: Regular Expression Help

2006-11-01 Thread Anshul Saxena

Ashish ,
you might have the [ in a recurring sequence using [*

On 11/1/06, John W. Krahn <[EMAIL PROTECTED]> wrote:


Ashish Srivastava wrote:
> I have a string which have multiple placeholder, for example:
>
> $str = 'Hello [[Name]], Your login id is  [[Login]] !!!";
>
> I want to replace all placeholder with some identifier. In above
example: identifier are Name and Login.
> The regular expression for this requirment is pretty staightward:
>
> $str =~ s/\[\[([\d\w\-]+)\]\]/$1/g;
>
> Now the problem is there could be  Nested Placeholders. For example:
>
> $str = 'Error is: id]]-[[message'
>
> so in above example if idenfiers are defined as:
>
> id = 1001
> Message = "Crash"
> 1001-Crash = "System overloaded"
>
> so output of my required regular expression for subsitution should be:
>
> Error is: System overloaded

$ perl -le'
my %t = (
id   => 1001,
message  => "Crash",
"1001-Crash" => "System overloaded",
);

my $str = q/Error is: id]]-[[message/;

print $str;

1 while $str =~ s/\[\[([\w-]+)]]/$t{$1}/g;

print $str;
'
Error is: id]]-[[message
Error is: System overloaded




John
--
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order.   -- Larry Wall

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





Re: Regular Expression Help

2006-11-01 Thread John W. Krahn
Ashish Srivastava wrote:
> I have a string which have multiple placeholder, for example: 
> 
> $str = 'Hello [[Name]], Your login id is  [[Login]] !!!";
> 
> I want to replace all placeholder with some identifier. In above example: 
> identifier are Name and Login.
> The regular expression for this requirment is pretty staightward:
> 
> $str =~ s/\[\[([\d\w\-]+)\]\]/$1/g;
> 
> Now the problem is there could be  Nested Placeholders. For example:
> 
> $str = 'Error is: id]]-[[message'
> 
> so in above example if idenfiers are defined as:
> 
> id = 1001
> Message = "Crash"
> 1001-Crash = "System overloaded"
> 
> so output of my required regular expression for subsitution should be:
> 
> Error is: System overloaded

$ perl -le'
my %t = (
id   => 1001,
message  => "Crash",
"1001-Crash" => "System overloaded",
);

my $str = q/Error is: id]]-[[message/;

print $str;

1 while $str =~ s/\[\[([\w-]+)]]/$t{$1}/g;

print $str;
'
Error is: id]]-[[message
Error is: System overloaded




John
-- 
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order.   -- Larry Wall

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




Re: regular expression help

2006-07-24 Thread Jonathan Weber

On 24 Jul 2006, at 5:48 PM, Rob Dixon wrote:

- The character wildcard '.' is just a dot within a character  
class, so [.\n]

will match only a dot or a newline


Ah, I hadn't realized that characters in [ ] are literals. That  
clears up a lot of the problem.


- Regexes aren't the best way of parsing HTML, unless the document  
is very
simple and predictable. Take a look at somthing like  
HTML::TreeBuilder if you're

doing this a lot on varying or non-trivial documents.


Yeah, I realize that it's not the best way to go about it, but I had  
many documents that were all the same, plus I figured this was a good  
excuse to learn regexes.


Thanks for the help!

Jonathan

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




Re: regular expression help

2006-07-24 Thread Dr.Ruud
"Jonathan Weber" schreef:

>   A Title
>
> I'm using a regular expression to find these and capture the name
> attribute ("w12234" in the example) and the contents of the h2 tag ("A
> Title").
>
> $_ =~ /\s*<\/a>\s*(+)<\/h2>/
>
> That's my regex, except I'm having trouble with the _ part. No
> matter what I seem to try, it won't match incidences where there's a
> newline somewhere in the string. I tried all manner of things,
> including [.\n], which if I understand correctly should match
> *everything*.

Not "[.\n]" (because that contains a literal dot), but "(?:.|\n)".
Or do a "s/\n/ /g" first.

But you don't need all that, see `perldoc perlre` about the s-modifier.

And much better: use a proper HTML parser, see CPAN.

-- 
Affijn, Ruud

"Gewoon is een tijger."



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




Re: regular expression help

2006-07-24 Thread Rob Dixon

Jonathan Weber wrote:
>
> Hi. I have some HTML files with lines like the following:
>
>   A Title
>
> I'm using a regular expression to find these and capture the name
> attribute ("w12234" in the example) and the contents of the h2 tag ("A
> Title").
>
> $_ =~ /\s*<\/a>\s*(+)<\/h2>/
>
> That's my regex, except I'm having trouble with the _ part. No
> matter what I seem to try, it won't match incidences where there's a
> newline somewhere in the string. I tried all manner of things,
> including [.\n], which if I understand correctly should match
> *everything*.
>
> I'm doing this on Windows; does the carriage return/line feed business
> have anything to do with this?

Hi Jonathan.

Some points:

- The character wildcard '.' is just a dot within a character class, so [.\n]
will match only a dot or a newline

- The /s modifier will force '.' to match absolutely anything, including a
newline. So you could write:

  $_ =~ /\s*<\/a>\s*(.+)<\/h2>/s;

but that isn't what you want as /.+/ will eat up all of the rest of the string
until the last  it finds. You could get away with /.+?/ but nicer is
/[^<]+/ which will match any number of any character except for an open angle
bracket

- If you're matching against $_ then you can omit it altogether:

  /\s*<\/a>\s*(.+)<\/h2>/;

does the same thing

- Enclosing a regex in slashes allows you to omit an implied m// operator, which
you have (i.e. /regex/ is the same as m/regex/). Putting the m back lets you use
whatever delimiters you want, so you don't have to escape the contained slashes
and can make it more readable:

  m#\s*\s*([^<]+)#;

- Regexes aren't the best way of parsing HTML, unless the document is very
simple and predictable. Take a look at somthing like HTML::TreeBuilder if you're
doing this a lot on varying or non-trivial documents.

- This program does what you want:

  use strict;
  use warnings;

  my $string = <  A
  Title
  HTML

  $string =~ m#\s*\s*([^<]+)#;

  print $1, "\n";
  print $2, "\n";

OUTPUT

  w12234
  A
  Title


I hope this helps.

Rob

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




Re: Regular expression help

2005-04-25 Thread Jay Savage
On 4/25/05, John W. Krahn <[EMAIL PROTECTED]> wrote:
> Owen wrote:
> > I found a message from Randal Schwartz, Message-ID:
> > <[EMAIL PROTECTED]>#1/1
> > which gave a regular expression for a valid Unix name,
> >
> >   /^(?=.*?\D)[a-z\d]+$/
> >
> > That works but why does it work?
> >
> > /
> >   ^   # Start of a string
> >(?=# 0 or 1 instance of
> >   .*? # anything but a newline
> >   \D  # Non digit
> >)  #
> >
> >   [a-z\d]+# All match a-z and any digit at
> >   $   # End of a string
> > /
> >
> >
> > I tried breaking it down like above but it still doesn't say "Must not be
> > all numbers and letters must be all lowercase"
> >
> > Any help in turning that re into plain words would be appreciated
> 
> (?=.*?\D) is a zero-width assertion so it doesn't affect the match which is
> /^[a-z\d]+$/ -- match a string whose only characters are a-z0-9.  When you add
> the zero-width assertion it ensures that there is at least one \D character in
> the match.
> 
> John

I think this may be part of the confusion, too:

> >(?=# 0 or 1 instance of
> >   .*? # anything but a newline

/.*?/ is not that same as /.?/.  /.?/ matches zero or 1 of any
character but the newline.  /.*?/, however, matches zero or more, just
like /.*/.  It's non-greedy, though, so it will stop matching at the
first occurance of \D instead of the last.  In this case it boils down
roughly to /(?=[^\D]{0,}\D/.

HTH,

--jay

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




Re: Regular expression help

2005-04-24 Thread John W. Krahn
Owen wrote:
I found a message from Randal Schwartz, Message-ID:
<[EMAIL PROTECTED]>#1/1
which gave a regular expression for a valid Unix name, 

/^(?=.*?\D)[a-z\d]+$/
That works but why does it work?
/
	^		# Start of a string 
	 (?=		# 0 or 1 instance of 
	.*?		# anything but a newline
	 	\D	# Non digit
	 )		#
	
	[a-z\d]+	# All match a-z and any digit at
		$	# End of a string
/

I tried breaking it down like above but it still doesn't say "Must not be
all numbers and letters must be all lowercase"
Any help in turning that re into plain words would be appreciated
(?=.*?\D) is a zero-width assertion so it doesn't affect the match which is
/^[a-z\d]+$/ -- match a string whose only characters are a-z0-9.  When you add
the zero-width assertion it ensures that there is at least one \D character in
the match.
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



RE: Regular expression help

2005-04-24 Thread Charles K. Clarkson
Owen  wrote:

: I found a message from Randal Schwartz, Message-ID:
: <[EMAIL PROTECTED]>#1/1
: which gave a regular expression for a valid Unix name,
:
:   /^(?=.*?\D)[a-z\d]+$/
:
: That works but why does it work?
:
: /
:   ^   # Start of a string
:(?=# 0 or 1 instance of

 (?=# Zero-width positive look ahead assertion.


:   .*? # anything but a newline
:)  #
:
:   [a-z\d]+# All match a-z and any digit at

[a-z\d]+# Match a-z (lowercase only) and any digit


:   $   # End of a string
: /
:
: I tried breaking it down like above but it still doesn't say
: "Must not be all numbers and letters must be all lowercase"
:
: Any help in turning that re into plain words would be
: appreciated

AFAIK, a (?= ... ) construct affects the contents of $&, $`,
and $'. Can you show any code immediately following this regular
expression and the whole line with it?


HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328


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




Re: regular expression help

2005-03-11 Thread Ing. Branislav Gerzo
Stone [S], on Friday, March 11, 2005 at 01:52 (-0800) made these
points:

S> Just one.  :)
S> Your expressions all say \d instead of \d? for the second digit in
S> each set, while the simple one correctly has \d?.   So your
S> expressions had an unfair advantage and as a result finish faster.

right, forget about 1.1.1 rule :)

S> Add \d? to your expressions, and you should find that "simple",
S> besides probably being the easiest to read, is also the most efficient
S> of the expressions listed.  (Note that I removed the obviously
S> inefficient ones.)

yes, and it is logical at end. The regexp using parentheses is always
slower, than longer, which doesn't. It have to "remember" values
inside them.

thanks to you, I discover some new things too :)

-- 

 ...m8s, cu l8r, Brano.

['It takes a giant to fight a giant' - H. Prym]



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




Re: regular expression help

2005-03-11 Thread Stone
> I hope I don't have any bugs here :)

Just one.  :)

Your expressions all say \d instead of \d? for the second digit in
each set, while the simple one correctly has \d?.   So your
expressions had an unfair advantage and as a result finish faster.

Add \d? to your expressions, and you should find that "simple",
besides probably being the easiest to read, is also the most efficient
of the expressions listed.  (Note that I removed the obviously
inefficient ones.)

use strict;
use warnings;
use Benchmark 'cmpthese';

my $field = '19.12.12';

cmpthese -5, {
   simple => sub {
   if ( $field =~ /^[1-9]\d?\.[1-9]\d?\.[1-9]\d?$/ ) {}
   },
   short => sub {
   if ( $field =~ /^([1-9]\d?\.){2}[1-9]\d?$/ ) {}
   },
   shortwoc => sub {
   if ( $field =~ /^(?:[1-9]\d?\.){2}[1-9]\d?$/ ) {}
   },
   trickywoc => sub {
   if ( $field =~ /^(?:[1-9]\d?(?:\.[1-9]\d?){2})$/ ) {}
   },
};

__END__   Rate short  shortwoc trickywocsimple
short  677138/s--  -23%  -25%  -40%
shortwoc   880536/s   30%--   -2%  -22%
trickywoc  901095/s   33%2%--  -20%
simple1127127/s   66%   28%   25%--

second benchmark:
my $field = '19.12.02';

Rate short  shortwoc trickywocsimple
short  927396/s--  -10%  -12%  -29%
shortwoc  1027728/s   11%--   -3%  -22%
trickywoc 1055892/s   14%3%--  -19%
simple1310837/s   41%   28%   24%--

> Have a nice day.

You too.  I learned a lot from this, so thanks.

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




Re: regular expression help

2005-03-11 Thread Ing. Branislav Gerzo
Stone [S], on Thursday, March 10, 2005 at 16:46 (-0800) typed:

S> That won't work either.  When you say ([1-9]\d?) you're telling it
S> "(If there is a match) capture the stuff in parentheses and store it."
S>  When you say "\1" you're telling the script "you know that first
S> batch of stuff you captured?  Well I want that here."  But it's not
S> the pattern, it's the literal substring of the match.

When I read your first line of reply, I realise, that you have right
again. Tomorrow was hard day for me, and also after some glassess of
wine I simply forget to some small details. And also I have to thank
you for nice and long explanation :) Ok, so I'm sorry, if I
confused someone, here is my explanation:

I don't like "simple" regular expressions, as was posted in first
message:

$field =~ /^[1-9]\d?\.[1-9]\d?\.[1-9]\d?$/;

that's too clear. I wanted change it (short), so I post 2 bad
examples. Clear shorting is:

$field =~ /^([1-9]\d?\.){2}[1-9]\d?$/;

but that's too much simple too :)

So let's continue how we can represent those rulez, this is a bit
tricky:

$field =~ /^([1-9]\d(?:\.[1-9]\d){2})$/;

and this is not shorter, but this way works too :):

$field =~ /^(?:(\d)(??{ $1 > 0 && $1 <= 9 ? "" : "(?!)" })\d\.){2}
   (\d)(??{ $2 > 0 && $2 <= 9 ? "" : "(?!)" })\d/x;

Ok, that's enough, now we can benchmark all those:

use strict;
use warnings;
use Benchmark 'cmpthese';

my $field = '19.12.12';

cmpthese -5, {
simple => sub {
if ( $field =~ /^[1-9]\d?\.[1-9]\d?\.[1-9]\d?$/ ) {}
},
short => sub {
if ( $field =~ /^([1-9]\d\.){2}[1-9]\d$/ ) {}
},
shortwoc => sub {
if ( $field =~ /^(?:[1-9]\d\.){2}[1-9]\d$/ ) {}
},
tricky => sub {
if ( $field =~ /^([1-9]\d(?:\.[1-9]\d){2})$/ ) {}
},
trickywoc => sub {
if ( $field =~ /^(?:[1-9]\d(?:\.[1-9]\d){2})$/ ) {}
},
long => sub {
if  ( $field =~ /^(?:(\d)(??{ $1 > 0 && $1 <= 9 ? "" : "(?!)" 
})\d\.){2}
 (\d)(??{ $2 > 0 && $2 <= 9 ? "" : "(?!)" 
})\d/x ) {}
},
using_var => sub {
my $reg = '[1-9]\d';
if ( $field =~ /^(?:$reg\.){2}$reg$/ ) {}
}
};

__END__

   Ratelong using_var   short  tricky  simple shortwoc trickywoc
long30584/s  --  -95%-95%-95%-98% -98%  -98%
using_var  582064/s   1803%---11%-14%-56% -60%  -62%
short  650382/s   2027%   12%  -- -3%-51% -56%  -58%
tricky 673134/s   2101%   16%  3%  ---49% -54%  -57%
simple1328337/s   4243%  128%104% 97%  -- -10%  -14%
shortwoc  1470620/s   4708%  153%126%118% 11%   --   -5%
trickywoc 1550263/s   4969%  166%138%130% 17%   5%--

second benchmark:
my $field = '19.12.02';

   Ratelong using_var shortwoc   short  simple  tricky trickywoc
long28809/s  --  -95% -98%-98%-98%-98%  -98%
using_var  606756/s   2006%-- -63%-63%-64%-64%  -66%
shortwoc  1627591/s   5550%  168%   -- -1% -3% -5%   -9%
short 1651154/s   5631%  172%   1%  -- -2% -3%   -8%
simple1681601/s   5737%  177%   3%  2%  -- -2%   -6%
tricky1707274/s   5826%  181%   5%  3%  2%  --   -5%
trickywoc 1790738/s   6116%  195%  10%  8%  6%  5%--

so conlusion is: I definitely would pick up
tricky WithOut Capturing: $field =~ /^(?:[1-9]\d(?:\.[1-9]\d){2})$/

I hope I don't have any bugs here :)

Have a nice day.

-- 

 ...m8s, cu l8r, Brano.

["Real knowledge is to know the extent of one's ignorance." - Confucius]



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




Re: regular expression help

2005-03-10 Thread Stone
> $field =~ /^(?:([1-9]\d?)\.){2}\1$/;

That won't work either.  When you say ([1-9]\d?) you're telling it
"(If there is a match) capture the stuff in parentheses and store it."
 When you say "\1" you're telling the script "you know that first
batch of stuff you captured?  Well I want that here."  But it's not
the pattern, it's the literal substring of the match.

Let's simplify it a little bit and consider this example:

10.15 =~ /^([1-9]\d?)\.\1$/;

In this case it would not match.  It works like this:

1.  [1-9]\d? matches 10.
2.  () stores that value "10" as \1 (or actually as $1, but within the
pattern you dereference it with \1).  Note that it doesn't store the
pattern "[1-9]\d?", but the actual substring "10".  So at this point,
the \1 becomes "10" and looks like this:

/^[1-9]\d?\.10$/

Obviously 15 !~ 10, so there is no match.

You would use that if you wanted to find things like 1.1 or 10.10.

With your expression:
10.15.20 =~ /^(?:([1-9]\d?)\.){2}\1$/;

1.  [1-9]\d? - Matches 10.
2.  () - Stores "10" as $1.  
3.  Pattern now looks like /^(?:([1-9]\d?)\.){2}10$/
4.  {2} - Requires a second match of (?:([1-9]\d?)\.).
5.  [1-9]\d? - Matches 15.  
6.  () - Stores "15" as $1 (overwriting the previous value).  (I may
be mistaken on what exactly happens here, but this is effectively the
case.  If so, someone more knowledgable will hopefully correct me.)
7.  Pattern now looks like /^(?:([1-9]\d?)\.){2}15$/
8.  20 !~ 15, so pattern does not match.

So your expression will match 10.10.10 or even 10.15.15, but it won't
match 10.15.20.

HTH

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




Re: regular expression help

2005-03-10 Thread Ing. Branislav Gerzo
Stone [S], on Thursday, March 10, 2005 at 12:51 (-0800) wrote the
following:

>> yes, and for complexity:
>> 
>> $field =~ /^([1-9]\d?)\.{2}\1$/;

S> I know you said that's untested, but I don't think it's correct.

yes, I'm sorry for that, should be this correct:

$field =~ /^(?:([1-9]\d?)\.){2}\1$/;

untested too :)


-- 

 ...m8s, cu l8r, Brano.

[Virus related taglines.]



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




Re: regular expression help

2005-03-10 Thread Stone
> yes, and for complexity:
> 
> $field =~ /^([1-9]\d?)\.{2}\1$/;

I know you said that's untested, but I don't think it's correct.

You're saying:
1.  ^ - Start
2.  ([1-9]\d?) -Any character 1-9 followed by zero or one digit characters.
3.  \.{2} - Two periods.
4.  \1 - The same sequence of characters as in #2.  (\1 references the
actual parenthetical match, not the expression.)
5.  $ - The end.

So your expression would match things like:
1..1
11..11

-- 
http://xstonedogx.heroesmarket.net

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




Re: regular expression help

2005-03-10 Thread Ing. Branislav Gerzo
Peter Rabbitson [PR], on Thursday, March 10, 2005 at 14:00 (-0500)
wrote:

PR> I think what he really wants is to throw a fit when there is a leading zero
PR> for which your solution won't cut it. Here is how I see it:

PR> $field =~ /^[1-9]\d?\.[1-9]\d?\.[1-9]\d?$/

yes, and for complexity:

$field =~ /^([1-9]\d?)\.{2}\1$/;

untested :)

-- 

 ...m8s, cu l8r, Brano.

["And don't call me `Chum'." -- Richard Sloat]



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




RE: regular expression help

2005-03-10 Thread Wagner, David --- Senior Programmer Analyst --- WGO
Peter Rabbitson wrote:
>> Simplest is change the {2} to {1,2} for all your entries. Now you
>> mush have from 1 to 2 digits. Wags ;)
> 
> 
> I think what he really wants is to throw a fit when there is a
> leading zero for which your solution won't cut it. Here is how I see
> it: 
> 
> $field =~ /^[1-9]\d?\.[1-9]\d?\.[1-9]\d?$/

Correct. I missed read the msg.
Wags ;)


***
This message contains 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]
 




Re: regular expression help

2005-03-10 Thread Peter Rabbitson
> Simplest is change the {2} to {1,2} for all your entries. Now you 
> mush have from 1 to 2 digits.
> Wags ;)


I think what he really wants is to throw a fit when there is a leading zero 
for which your solution won't cut it. Here is how I see it:

$field =~ /^[1-9]\d?\.[1-9]\d?\.[1-9]\d?$/



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




RE: regular expression help

2005-03-10 Thread Wagner, David --- Senior Programmer Analyst --- WGO
CM Analyst wrote:
> I am quite new to programming and Perl, so please bear
> with me.
> 
> I have a requirement to check the format of a field
> before a record can be saved. The format of the field
> needs to be double digit value separated by a .
> (period) like "00.00.00". This I managed to do using
> the following:
> 
> use strict;
> use warnings;
> 
> my $field;
> 
> print "This program will verify field value.\n";
> 
> print "Enter field value:  ";
> 
> $field = ;
> 
> chomp ($field);
> 
> if ( $field =~ /^[0-9]{2}\.[0-9]{2}\.[0-9]{2}$/ )
Simplest is change the {2} to {1,2} for all your entries. Now you mush 
have from 1 to 2 digits.
Wags ;)
> 
> {
> print "Value is OK";
> }
> else
> {
> print "Value is Wrong. Please enter a double digit
> value like 00.00.00";
> }
> ###
> 
> However, the requirement has changed in that we while
> we want to allow the "00.00.00" format we do not a 0
> (zero) to be a leading value.
> 
> How can this be accomplished?
> 
> Please advise.
> 
> Regards.
> 
> Amad
> 
> 
> 
> __
> Do you Yahoo!?
> Yahoo! Small Business - Try our new resources site!
> http://smallbusiness.yahoo.com/resources/



***
This message contains 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]
 




Re: Regular expression help

2004-10-22 Thread Gunnar Hjalmarsson
Bee wrote:
I'd do a little add on for the string, so it much easier for split.
# usuw;
my $line = "M:356 358 386 R:#132 W1:319 NRT:32 R:#132";
print $line . "\n";
$line =~ s/(\s)(\w{1,}:)/\x00$2/g; # So I add extra delimiters here.
print $line . "\n";
my @d = split /\x00/, $line;
print "<$_> " for @d;
But only if you sure that char is not exist with the data string,
you can use. Otherwise, use other approach, or other delimiter.
Other approaches:
my @y;
push @y, "$1 $2" while $line =~ /(\w+):([^A-Z]+)(?: |$)/g;
or
my @y = map { tr/:/ /; $_ } $line =~ /(\w+:[^A-Z]+)(?: |$)/g;
Also, why is $y[0] undefined or null, scalar (@y) is 6.
That's explained in "perldoc -f split".
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: Regular expression help

2004-10-22 Thread Bee

> __DATA__
> M:356 358 386 R:#132 W1:319 NRT:32 R:#132
>


>
> but I would really like it to capture the first part of the element so
that the result would be;
>
> M:356 358 386 R:#132 W1:319 NRT:32 R:#132
> $y[0]
> $y[1] M 356 358 386
> $y[2] R #132
> $y[3] W1 319
> $y[4] NRT 32
> $y[5] R #132
>

I'd do a little add on for the string, so it much easier for split.

# usuw;
my $line = "M:356 358 386 R:#132 W1:319 NRT:32 R:#132";
print $line . "\n";
$line =~ s/(\s)(\w{1,}:)/\x00$2/g; # So I add extra delimiters here.
print $line . "\n";

my @d = split /\x00/, $line;
print "<$_> " for @d;

But only if you sure that char is not exist with the data string,
you can use. Otherwise, use other approach, or other delimiter.

>
> Also, why is $y[0] undefined or null, scalar (@y) is 6.

I don't know how to tell, but I think you want \s , but not \b.

HTH,
Bee



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




RE: Regular expression help

2003-08-19 Thread EUROSPACE SZARINDAR

Hi Rob, 


You are totally right your exemple (' data11 '' dat"a12' 'data13') should
raise an error and this is normal. I will nethertheless look carefully for
the Text::CSV module.

 Thanks 

Michel




-Message d'origine-
De: Rob Anderson [mailto:[EMAIL PROTECTED]
Date: lundi 18 août 2003 17:34
À: [EMAIL PROTECTED]
Objet: Re: Regular expression help


>
>"Eurospace Szarindar" <[EMAIL PROTECTED]> wrote in
message >news:[EMAIL PROTECTED]
>
>Thanks you, it works fine. Could you explain me why have you added the \1 ?

Hi,

A quick breakdown...


/(['"])(((''|"")|[^'"])*?)\1(\s|$)/g
 ^^
1  
  2
  ^^
  3


1) This is picking up either a single or double quote

2) This is scoping up any quotes pairs, and is being carefull not
   to match quotes on thier own.

3) In a regex \1, \2 etc.. will match the same sequence of characters
matched
   earlier in the same-numbered pair of parentheses, in this case, it means
   that were making sure the opening and closing quotes are the same by
mathching
   that same character as in part 1.

Explaining it like this has made me spot a problem. The regex you really
want is

m/(['"])(((''|"")|[^\1])*?)\1(\s|$)/g

This way our 'scoping up' part matches any paired quotes or anything other
than
our closing quote.


The following test data wouldn't have worked...

' data11 '' dat"a12' 'data13'

>
>I will have a look at Text::CSV
>

Please do, my mistake above shows you why you shouldn't reinvent this stuff
if you can
get away with it. :-)

Ta

Rob


>
>Michel
>
>-Message d'origine-
>De: Rob Anderson [mailto:[EMAIL PROTECTED]






-- 
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: Regular expression help

2003-08-18 Thread Rob Anderson
>
>"Eurospace Szarindar" <[EMAIL PROTECTED]> wrote in
message >news:[EMAIL PROTECTED]
>
>Thanks you, it works fine. Could you explain me why have you added the \1 ?

Hi,

A quick breakdown...


/(['"])(((''|"")|[^'"])*?)\1(\s|$)/g
 ^^
1  
  2
  ^^
  3


1) This is picking up either a single or double quote

2) This is scoping up any quotes pairs, and is being carefull not
   to match quotes on thier own.

3) In a regex \1, \2 etc.. will match the same sequence of characters
matched
   earlier in the same-numbered pair of parentheses, in this case, it means
   that were making sure the opening and closing quotes are the same by
mathching
   that same character as in part 1.

Explaining it like this has made me spot a problem. The regex you really
want is

m/(['"])(((''|"")|[^\1])*?)\1(\s|$)/g

This way our 'scoping up' part matches any paired quotes or anything other
than
our closing quote.


The following test data wouldn't have worked...

' data11 '' dat"a12' 'data13'

>
>I will have a look at Text::CSV
>

Please do, my mistake above shows you why you shouldn't reinvent this stuff
if you can
get away with it. :-)

Ta

Rob


>
>Michel
>
>-Message d'origine-
>De: Rob Anderson [mailto:[EMAIL PROTECTED]






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



RE: Regular expression help

2003-08-18 Thread EUROSPACE SZARINDAR

Thanks you, it works fine. Could you explain me why have you added the \1 ?
I will have a look at Text::CSV

Michel

-Message d'origine-
De: Rob Anderson [mailto:[EMAIL PROTECTED]
Date: lundi 18 août 2003 16:39
À: [EMAIL PROTECTED]
Objet: Re: Regular expression help



"Eurospace Szarindar" <[EMAIL PROTECTED]> wrote in
message news:[EMAIL PROTECTED]
> Hi,
>
> I tried to write a script to extrat data from the given DATA but I can
find
> the right regular expression to do that.

Hi Szarindar,

Firstly why are you using this format and trying to parse it yourself? If
you've got control of your data, use something like Text::CSV. The guy who
maintains your code will thank you for it.

otherwise, this seems to work (you'll have to print with $2 though)...

/(['"])(((''|"")|[^'"])*?)\1(\s|$)/g

HTH

Rob Anderson

> RULE: I need to catch everything between quotes (single or double) and if
> inside exists a repeated quote (single or double) it is not seen as end of
> the match.
>
> #!/usr/bin/perl -w
>
> use strict;
>
> my $begin = '[\",\']'; #
> my $end = '[\",\']'; #
> my $pattern = "${begin}(.*?)${end}"
>
> while () {
> print "line content $_ \n"
> while ( /$pattern/g ){
> print "line $. found : $1\n"
> }
>
> }
>
>
> __DATA__
> ' data11 '' data12' 'data13'
> " data21 "" data22" "data23"
> " data31 '' data32" "" "data34"
> "data41" "data42" "data43" "__--data44"
> """"  "''" '""' ''''
>
>
>
> Result should be
> 1:( data11 '' data12)
> 2:(data13)
> 3:( data21 "" data22)
> 4:(data23)
> 5:(data31 '' data32)
> 6:()
> 7:(data34)
> 8:(data41)
> 9:(data42)
> 10:(data43)
> 11:(__--data44)
> 12:("")
> 13:('')
> 14:("")
> 15:('')
>
>
> It could be resolved by replacing the \"{2} or \'{2} by a "[EMAIL PROTECTED]" and
> alterwards relacing it back to the previous value but it is not very
smart.
>
>
>
> great thanks in advance
>
> Michel



-- 
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: Regular expression help

2003-08-18 Thread Rob Anderson

"Eurospace Szarindar" <[EMAIL PROTECTED]> wrote in
message news:[EMAIL PROTECTED]
> Hi,
>
> I tried to write a script to extrat data from the given DATA but I can
find
> the right regular expression to do that.

Hi Szarindar,

Firstly why are you using this format and trying to parse it yourself? If
you've got control of your data, use something like Text::CSV. The guy who
maintains your code will thank you for it.

otherwise, this seems to work (you'll have to print with $2 though)...

/(['"])(((''|"")|[^'"])*?)\1(\s|$)/g

HTH

Rob Anderson

> RULE: I need to catch everything between quotes (single or double) and if
> inside exists a repeated quote (single or double) it is not seen as end of
> the match.
>
> #!/usr/bin/perl -w
>
> use strict;
>
> my $begin = '[\",\']'; #
> my $end = '[\",\']'; #
> my $pattern = "${begin}(.*?)${end}"
>
> while () {
> print "line content $_ \n"
> while ( /$pattern/g ){
> print "line $. found : $1\n"
> }
>
> }
>
>
> __DATA__
> ' data11 '' data12' 'data13'
> " data21 "" data22" "data23"
> " data31 '' data32" "" "data34"
> "data41" "data42" "data43" "__--data44"
>   "''" '""' 
>
>
>
> Result should be
> 1:( data11 '' data12)
> 2:(data13)
> 3:( data21 "" data22)
> 4:(data23)
> 5:(data31 '' data32)
> 6:()
> 7:(data34)
> 8:(data41)
> 9:(data42)
> 10:(data43)
> 11:(__--data44)
> 12:("")
> 13:('')
> 14:("")
> 15:('')
>
>
> It could be resolved by replacing the \"{2} or \'{2} by a "[EMAIL PROTECTED]" and
> alterwards relacing it back to the previous value but it is not very
smart.
>
>
>
> great thanks in advance
>
> Michel



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



RE: Regular Expression help

2002-09-24 Thread Mark Anderson

see my comments at bottom...

-Original Message-
From: Shaun Bramley [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, September 24, 2002 4:39 PM
To: [EMAIL PROTECTED]
Subject: Regular Expression help


Hi all.

I am hoping that someone can help me determine what is wronf with my regualr
expression.

background info: @array contains 'text', numbers, INT, or TINYINT.

I am trying to identify if the array element is a number.

What I have right now is:

if($array[$x] =~ /\d{1,3}?/)
{
.do something
}

Unfortunately this if statement never appears to come true.

thank you

Shaun

-Response Follows--

I'm not clear on what your problem is.  Could you give some examples of what
in the array you want to "do something", and some examples that you don't?
Perhaps show us more of the code than just the regexp?

I quickly wrote up the following code (using your regexp):

push @array,'1';
push @array,'xyzzy';
push @array,'1.234';
push @array,"0x1234";
push @array,3;

for ($x=-1;$x++<$#array;) {
if ($array[$x] =~ /\d{1,3}?/) {
print "Yes: "
} else {
print "No : "
}
print $array[$x]."\n";
}

which produces:
Yes: 1
No : xyzzy
Yes: 1.234
Yes: 0x1234
Yes: 3

which appears to me to be correct.

/\/\ark


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




RE: Regular Expression help

2002-09-24 Thread nkuipers

>if($array[$x] =~ /\d{1,3}?/)
>{
>...do something
>}
>
>Unfortunately this if statement never appears to come true.

That's because you have two quantifiers specified, the {1,3} and the ?.

for (@array) { 
if ( m/^\d+$/ ) { #regex breaks on decimal numbers
do something... 
}
}


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




RE: regular expression help....

2002-09-12 Thread david

David --- Senior Programmer Analyst --- Wgo Wagner wrote:

> Your log shows a space between the time and hyphen and hyphen and
> Micro. You dont' have that in the regex and even more so, there is no
> hyphen before Adapter log.
> 
> You might want:
> /^(\d\d-\d\d-\d{4})\s+(\d\d:\d\d:\d\d\.\d\d).+Adapter
> log\s+(opened|closed)/i
> 
> Anchor with the ^ and you will have date in $1, time in $2 and
> opened or closed in $3.
> A shot.
> Wags ;)

you can avoid putting tons of \d in your reg by using:

my($d,$t) = (split(/\s+/))[0,1];
print "$d,$t\n";

__END__

but a reg. expression should be much faster.

david

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




RE: regular expression help....

2002-09-11 Thread Wagner, David --- Senior Programmer Analyst --- WGO

Your log shows a space between the time and hyphen and hyphen and
Micro. You dont' have that in the regex and even more so, there is no hyphen
before Adapter log.

You might want:
/^(\d\d-\d\d-\d{4})\s+(\d\d:\d\d:\d\d\.\d\d).+Adapter
log\s+(opened|closed)/i

Anchor with the ^ and you will have date in $1, time in $2 and
opened or closed in $3.
A shot.
Wags ;)

-Original Message-
From: Steve [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, September 11, 2002 08:12
To: [EMAIL PROTECTED]
Subject: regular expression help


I have the following line in a log file:

09-07-2002 11:39:25.95 - Microsoft Dial Up Adapter log opened.

The date and time will always change but the after that it's always 
consistent (well opened will sometimes be closed)  I need to get the entire 
date in a variable and the entire time in a variable.  I will compare the 
difference between open and close and place THAT into a cumulative variable.

Anyway this the rexexp I have to get the date and time but it's not
matching:

/(\d\d-\d\d-\d{4}) (\d\d:\d\d:\d\d\.\d\d)-(Adapter log)/

Now if I just do it like /(Adapter log)/ I get a match on Adapter log, 
which leads me to think that the problem is somewhere with my digit
matching.

Thanks



-

The three most dangerous things are a programmer with a soldering iron, a 
manager who codes, and a user who gets ideas.



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


**
This message contains 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]




Re: Regular Expression Help sought

2002-07-04 Thread Katy Brownfield

One thing I would add is that the inner pair of parentheses is used to
isolate ^|\n\n from the rest of the pattern so it is clear what the | is
operating on. /cat|blue fish/ matches "cat" or "blue fish" but
/(cat|blue) fish/ matches "cat fish" or "blue fish". (The parentheses
also capture the thing that was matched in $2, but we don't need it.
(?:^|\n\n) would prevent it from capturing the match, but capturing
doesn't hurt anything in this case and the pattern is easier to read.)

Katy


Nigel Peck wrote:
> 
> s/((^|\n\n).+?)\n/$1 /g;
> 
> s/   substitute
> ( put this is $1
> (^  the start of the file
> |  or
> \n\n)  two newlines
> ..+?  followed by 1 or more characters up until a
> ) stop putting it in $1
> \n  newline
> / with
> $1 /the text captured above followed by a space
> g;keep doing it until you can't match anymore
> 
> >>> Sunish Kapoor <[EMAIL PROTECTED]> 07/04/02 04:27pm >>>
> Dear Katy,
> 
> It works great after the changed the regular expression to as given by
> u
> below..!
> Thanks a ton for the help.but may I request for a small explanation
> of the
> line
> $file =~ s/((^|\n\n).+?)\n/$1 /g;
> 
> Sunish
> 
> Katy Brownfield wrote:
> 
> > Or, instead of changing the input file, change the regular expression
> to
> > also detect the beginning of the string.
> >
> > $file =~ s/((^|\n\n).+?)\n/$1 /g;
> >
> > Katy
> >
> > Timothy Johnson wrote:
> > >
> > >
> > > I think you'll need 2 blank lines.
> > >
> > > -Original Message-
> > > From: Sunish Kapoor
> > > To: Nigel Peck
> > > Cc: [EMAIL PROTECTED]
> > > Sent: 7/3/02 6:51 PM
> > > Subject: Re: Regular Expression Help sought
> > >
> > > Dear Nigel,
> > >
> > > Thanks a ton for the script..It works fine though it skips the
> first
> > > record
> > > even though I make
> > > the file begin with a blank line by simply hitting enter !
> > >
> > > Regards
> > >
> > > Sunish
> > > Nigel Peck wrote:
> > >
> > > > My first attempt, which may be a bit simplified, would be to
> > > substitute
> > > > any newline, which occured at the end of a line which was
> preceeded by
> > > 2
> > > > consecutive newlines, with a space. This relies on the format of
> the
> > > > file being as shown for every company. It also may miss the
> first
> > > > company in the file if the file doesn't start with a blank line.
> > > >
> > > > So
> > > >
> > > > undef $/;
> > > > $file = ;
> > > > $file =~ s/(\n\n.+?)\n/$1 /g;
> > > > print $file;
> > > >
> > > > [untested]
> > > >
> > > > HTH
> > > > Nigel
> > > >
> > > > >>> [EMAIL PROTECTED] 07/03/02 10:52pm >>>
> > > > Hi  All,
> > > >
> > > > I am new to Perl and need help to solve this one !
> > > >
> > > > I have a txt file and the contents of the file are as below  :
> > > >
> > > > ---CONTENTS   OF   TEXT
> FILE--
> > > > Abdullah Ahmed Hassan
> > > > Trading
> > > > Location Ruwi Souk St, Ruwi
> > > > Bus Hrs 0930-1300:1630-2200
> > > > P.O. Box 197 Ruwi Code 112
> > > > Phone 708940
> > > > Fax 794156
> > > > Key Staff Abdullah Ahmed Hassan
> > > > Mohammad Hussain Ahmed Hassan
> > > > Irfan Ahmed
> > > > Mohammad Asim
> > > > Activities :3410
> > > > Email : [EMAIL PROTECTED]
> > > >
> > > > Abu Ali Trading & Cont
> > > > Est
> > > > Location Azaiba
> > > > B us H rs 0700-1200; 1500-1900
> > > > P.O. Box 1695 C. P. 0. Code 111
> > > > Phone 595324
> > > > Key Staff K. Sasi, Prop
> > > > Ali Suleiman Al Ghubshi, Sponsor
> > > > Activities 2700
> > > >
> > > > Abu Al Dahab Trading & Contg
> > > > Est
> > > > Location 23rd July St, Opp Al Ghobish
> > > > Furniture Showroom
> > > > Bus Hrs 0800-1300 (Sat-Thu); 1600-1900 (Sat-
> > > > Fri)
> > > > P.O. Box 1254 Salalah Code 211
> > > > Phone 297879
> > > > Fax 297879
> >

Re: Regular Expression Help sought

2002-07-04 Thread Nigel Peck

s/((^|\n\n).+?)\n/$1 /g;

s/   substitute
( put this is $1
(^  the start of the file
|  or
\n\n)  two newlines
..+?  followed by 1 or more characters up until a
) stop putting it in $1
\n  newline
/ with
$1 /the text captured above followed by a space
g;keep doing it until you can't match anymore

>>> Sunish Kapoor <[EMAIL PROTECTED]> 07/04/02 04:27pm >>>
Dear Katy,

It works great after the changed the regular expression to as given by
u
below..!
Thanks a ton for the help.but may I request for a small explanation
of the
line
$file =~ s/((^|\n\n).+?)\n/$1 /g;

Sunish

Katy Brownfield wrote:

> Or, instead of changing the input file, change the regular expression
to
> also detect the beginning of the string.
>
> $file =~ s/((^|\n\n).+?)\n/$1 /g;
>
> Katy
>
> Timothy Johnson wrote:
> >
> >
> > I think you'll need 2 blank lines.
> >
> > -Original Message-
> > From: Sunish Kapoor
> > To: Nigel Peck
> > Cc: [EMAIL PROTECTED] 
> > Sent: 7/3/02 6:51 PM
> > Subject: Re: Regular Expression Help sought
> >
> > Dear Nigel,
> >
> > Thanks a ton for the script..It works fine though it skips the
first
> > record
> > even though I make
> > the file begin with a blank line by simply hitting enter !
> >
> > Regards
> >
> > Sunish
> > Nigel Peck wrote:
> >
> > > My first attempt, which may be a bit simplified, would be to
> > substitute
> > > any newline, which occured at the end of a line which was
preceeded by
> > 2
> > > consecutive newlines, with a space. This relies on the format of
the
> > > file being as shown for every company. It also may miss the
first
> > > company in the file if the file doesn't start with a blank line.
> > >
> > > So
> > >
> > > undef $/;
> > > $file = ;
> > > $file =~ s/(\n\n.+?)\n/$1 /g;
> > > print $file;
> > >
> > > [untested]
> > >
> > > HTH
> > > Nigel
> > >
> > > >>> [EMAIL PROTECTED] 07/03/02 10:52pm >>>
> > > Hi  All,
> > >
> > > I am new to Perl and need help to solve this one !
> > >
> > > I have a txt file and the contents of the file are as below  :
> > >
> > > ---CONTENTS   OF   TEXT  
FILE--
> > > Abdullah Ahmed Hassan
> > > Trading
> > > Location Ruwi Souk St, Ruwi
> > > Bus Hrs 0930-1300:1630-2200
> > > P.O. Box 197 Ruwi Code 112
> > > Phone 708940
> > > Fax 794156
> > > Key Staff Abdullah Ahmed Hassan
> > > Mohammad Hussain Ahmed Hassan
> > > Irfan Ahmed
> > > Mohammad Asim
> > > Activities :3410
> > > Email : [EMAIL PROTECTED] 
> > >
> > > Abu Ali Trading & Cont
> > > Est
> > > Location Azaiba
> > > B us H rs 0700-1200; 1500-1900
> > > P.O. Box 1695 C. P. 0. Code 111
> > > Phone 595324
> > > Key Staff K. Sasi, Prop
> > > Ali Suleiman Al Ghubshi, Sponsor
> > > Activities 2700
> > >
> > > Abu Al Dahab Trading & Contg
> > > Est
> > > Location 23rd July St, Opp Al Ghobish
> > > Furniture Showroom
> > > Bus Hrs 0800-1300 (Sat-Thu); 1600-1900 (Sat-
> > > Fri)
> > > P.O. Box 1254 Salalah Code 211
> > > Phone 297879
> > > Fax 297879
> > > Key Staff Syed Tajudeen Madani, Gen Mgr
> > > Activities 2660
> > > ---CONTENTS  OF TEXT FILE--
> > >
> > > The names of three companies as above are:
> > >
> > > Abdullah Ahmed Hassan
> > > Trading
> > >
> > > Abu Ali Trading & Cont
> > > Est
> > >
> > > Abu Al Dahab Trading & Contg
> > > Est
> > >
> > > I want the data this way .
> > >
> > > ---DATA WANTED THIS WAY
> > > Abdullah Ahmed Hassan Trading
> > > Location Ruwi Souk St, Ruwi
> > > Bus Hrs 0930-1300:1630-2200
> > > P.O. Box 197 Ruwi Code 112
> > > Phone 708940
> > > Fax 794156
> > > Key Staff Abdullah Ahmed Hassan
> > > Mohammad Hussain Ahmed Hassan
> > > Irfan Ahmed
> > > Mohammad Asim
> > > Activities :3410
> > > Email : [EMAIL PROTECTED] 
> > >
> > > Abu Ali Trading & Cont Est
> > > Location Azaiba
> > > B us H rs 0700-1200; 1500-1900
> > > 

Re: Regular Expression Help sought

2002-07-03 Thread Sunish Kapoor

Dear Katy,

It works great after the changed the regular expression to as given by u
below..!
Thanks a ton for the help.but may I request for a small explanation of the
line
$file =~ s/((^|\n\n).+?)\n/$1 /g;

Sunish

Katy Brownfield wrote:

> Or, instead of changing the input file, change the regular expression to
> also detect the beginning of the string.
>
> $file =~ s/((^|\n\n).+?)\n/$1 /g;
>
> Katy
>
> Timothy Johnson wrote:
> >
> >
> > I think you'll need 2 blank lines.
> >
> > -Original Message-
> > From: Sunish Kapoor
> > To: Nigel Peck
> > Cc: [EMAIL PROTECTED]
> > Sent: 7/3/02 6:51 PM
> > Subject: Re: Regular Expression Help sought
> >
> > Dear Nigel,
> >
> > Thanks a ton for the script..It works fine though it skips the first
> > record
> > even though I make
> > the file begin with a blank line by simply hitting enter !
> >
> > Regards
> >
> > Sunish
> > Nigel Peck wrote:
> >
> > > My first attempt, which may be a bit simplified, would be to
> > substitute
> > > any newline, which occured at the end of a line which was preceeded by
> > 2
> > > consecutive newlines, with a space. This relies on the format of the
> > > file being as shown for every company. It also may miss the first
> > > company in the file if the file doesn't start with a blank line.
> > >
> > > So
> > >
> > > undef $/;
> > > $file = ;
> > > $file =~ s/(\n\n.+?)\n/$1 /g;
> > > print $file;
> > >
> > > [untested]
> > >
> > > HTH
> > > Nigel
> > >
> > > >>> [EMAIL PROTECTED] 07/03/02 10:52pm >>>
> > > Hi  All,
> > >
> > > I am new to Perl and need help to solve this one !
> > >
> > > I have a txt file and the contents of the file are as below  :
> > >
> > > ---CONTENTS   OF   TEXT   FILE--
> > > Abdullah Ahmed Hassan
> > > Trading
> > > Location Ruwi Souk St, Ruwi
> > > Bus Hrs 0930-1300:1630-2200
> > > P.O. Box 197 Ruwi Code 112
> > > Phone 708940
> > > Fax 794156
> > > Key Staff Abdullah Ahmed Hassan
> > > Mohammad Hussain Ahmed Hassan
> > > Irfan Ahmed
> > > Mohammad Asim
> > > Activities :3410
> > > Email : [EMAIL PROTECTED]
> > >
> > > Abu Ali Trading & Cont
> > > Est
> > > Location Azaiba
> > > B us H rs 0700-1200; 1500-1900
> > > P.O. Box 1695 C. P. 0. Code 111
> > > Phone 595324
> > > Key Staff K. Sasi, Prop
> > > Ali Suleiman Al Ghubshi, Sponsor
> > > Activities 2700
> > >
> > > Abu Al Dahab Trading & Contg
> > > Est
> > > Location 23rd July St, Opp Al Ghobish
> > > Furniture Showroom
> > > Bus Hrs 0800-1300 (Sat-Thu); 1600-1900 (Sat-
> > > Fri)
> > > P.O. Box 1254 Salalah Code 211
> > > Phone 297879
> > > Fax 297879
> > > Key Staff Syed Tajudeen Madani, Gen Mgr
> > > Activities 2660
> > > ---CONTENTS  OF TEXT FILE--
> > >
> > > The names of three companies as above are:
> > >
> > > Abdullah Ahmed Hassan
> > > Trading
> > >
> > > Abu Ali Trading & Cont
> > > Est
> > >
> > > Abu Al Dahab Trading & Contg
> > > Est
> > >
> > > I want the data this way .
> > >
> > > ---DATA WANTED THIS WAY
> > > Abdullah Ahmed Hassan Trading
> > > Location Ruwi Souk St, Ruwi
> > > Bus Hrs 0930-1300:1630-2200
> > > P.O. Box 197 Ruwi Code 112
> > > Phone 708940
> > > Fax 794156
> > > Key Staff Abdullah Ahmed Hassan
> > > Mohammad Hussain Ahmed Hassan
> > > Irfan Ahmed
> > > Mohammad Asim
> > > Activities :3410
> > > Email : [EMAIL PROTECTED]
> > >
> > > Abu Ali Trading & Cont Est
> > > Location Azaiba
> > > B us H rs 0700-1200; 1500-1900
> > > P.O. Box 1695 C. P. 0. Code 111
> > > Phone 595324
> > > Key Staff K. Sasi, Prop
> > > Ali Suleiman Al Ghubshi, Sponsor
> > > Activities 2700
> > >
> > > Abu Al Dahab Trading & Contg Est
> > > Location 23rd July St, Opp Al Ghobish
> > > Furniture Showroom
> > > Bus Hrs 0800-1300 (Sat-Thu); 1600-1900 (Sat-
> > > Fri)
> > > P.O. Box 1254 Salalah Code

Re: Regular Expression Help sought

2002-07-03 Thread Katy Brownfield

Or, instead of changing the input file, change the regular expression to
also detect the beginning of the string.

$file =~ s/((^|\n\n).+?)\n/$1 /g;

Katy

Timothy Johnson wrote:
> 
> 
> I think you'll need 2 blank lines.
> 
> -Original Message-
> From: Sunish Kapoor
> To: Nigel Peck
> Cc: [EMAIL PROTECTED]
> Sent: 7/3/02 6:51 PM
> Subject: Re: Regular Expression Help sought
> 
> Dear Nigel,
> 
> Thanks a ton for the script..It works fine though it skips the first
> record
> even though I make
> the file begin with a blank line by simply hitting enter !
> 
> Regards
> 
> Sunish
> Nigel Peck wrote:
> 
> > My first attempt, which may be a bit simplified, would be to
> substitute
> > any newline, which occured at the end of a line which was preceeded by
> 2
> > consecutive newlines, with a space. This relies on the format of the
> > file being as shown for every company. It also may miss the first
> > company in the file if the file doesn't start with a blank line.
> >
> > So
> >
> > undef $/;
> > $file = ;
> > $file =~ s/(\n\n.+?)\n/$1 /g;
> > print $file;
> >
> > [untested]
> >
> > HTH
> > Nigel
> >
> > >>> [EMAIL PROTECTED] 07/03/02 10:52pm >>>
> > Hi  All,
> >
> > I am new to Perl and need help to solve this one !
> >
> > I have a txt file and the contents of the file are as below  :
> >
> > ---CONTENTS   OF   TEXT   FILE--
> > Abdullah Ahmed Hassan
> > Trading
> > Location Ruwi Souk St, Ruwi
> > Bus Hrs 0930-1300:1630-2200
> > P.O. Box 197 Ruwi Code 112
> > Phone 708940
> > Fax 794156
> > Key Staff Abdullah Ahmed Hassan
> > Mohammad Hussain Ahmed Hassan
> > Irfan Ahmed
> > Mohammad Asim
> > Activities :3410
> > Email : [EMAIL PROTECTED]
> >
> > Abu Ali Trading & Cont
> > Est
> > Location Azaiba
> > B us H rs 0700-1200; 1500-1900
> > P.O. Box 1695 C. P. 0. Code 111
> > Phone 595324
> > Key Staff K. Sasi, Prop
> > Ali Suleiman Al Ghubshi, Sponsor
> > Activities 2700
> >
> > Abu Al Dahab Trading & Contg
> > Est
> > Location 23rd July St, Opp Al Ghobish
> > Furniture Showroom
> > Bus Hrs 0800-1300 (Sat-Thu); 1600-1900 (Sat-
> > Fri)
> > P.O. Box 1254 Salalah Code 211
> > Phone 297879
> > Fax 297879
> > Key Staff Syed Tajudeen Madani, Gen Mgr
> > Activities 2660
> > ---CONTENTS  OF TEXT FILE--
> >
> > The names of three companies as above are:
> >
> > Abdullah Ahmed Hassan
> > Trading
> >
> > Abu Ali Trading & Cont
> > Est
> >
> > Abu Al Dahab Trading & Contg
> > Est
> >
> > I want the data this way .
> >
> > ---DATA WANTED THIS WAY
> > Abdullah Ahmed Hassan Trading
> > Location Ruwi Souk St, Ruwi
> > Bus Hrs 0930-1300:1630-2200
> > P.O. Box 197 Ruwi Code 112
> > Phone 708940
> > Fax 794156
> > Key Staff Abdullah Ahmed Hassan
> > Mohammad Hussain Ahmed Hassan
> > Irfan Ahmed
> > Mohammad Asim
> > Activities :3410
> > Email : [EMAIL PROTECTED]
> >
> > Abu Ali Trading & Cont Est
> > Location Azaiba
> > B us H rs 0700-1200; 1500-1900
> > P.O. Box 1695 C. P. 0. Code 111
> > Phone 595324
> > Key Staff K. Sasi, Prop
> > Ali Suleiman Al Ghubshi, Sponsor
> > Activities 2700
> >
> > Abu Al Dahab Trading & Contg Est
> > Location 23rd July St, Opp Al Ghobish
> > Furniture Showroom
> > Bus Hrs 0800-1300 (Sat-Thu); 1600-1900 (Sat-
> > Fri)
> > P.O. Box 1254 Salalah Code 211
> > Phone 297879
> > Fax 297879
> > Key Staff Syed Tajudeen Madani, Gen Mgr
> > Activities 2660
> > ---DATA WANTED THIS WAY
> >
> > I want PERL to make the name of the company to come in
> > one line as it has done for all three records.
> >
> > I request your help solving this.
> >
> > Regards
> >
> > Sunish Kapoor
> >
> > ITM Business Solutions
> > Unit 4
> > Nine Trees Trading Estate
> > Morthen Road
> > Rotherham
> > S66 9JG
> >
> > Reception
> > Tel: 01709 703288
> > Fax: 01709 701549
> >
> > Help Desk
> > Tel:01709 530424
> > Fax: 01709 702159
> >
> > CONFIDENTIALITY NOTICE: This message is intended only for the use of
> > the individual or entity to which it is addressed, and may contain
> > information that is privileged, confidential and exempt from
> disclosure
> > under applicable law.
> >
> > --
> > 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]
> 
> --
> 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: Regular Expression Help sought

2002-07-03 Thread Timothy Johnson

 
I think you'll need 2 blank lines.

-Original Message-
From: Sunish Kapoor
To: Nigel Peck
Cc: [EMAIL PROTECTED]
Sent: 7/3/02 6:51 PM
Subject: Re: Regular Expression Help sought


Dear Nigel,

Thanks a ton for the script..It works fine though it skips the first
record
even though I make
the file begin with a blank line by simply hitting enter !

Regards

Sunish
Nigel Peck wrote:

> My first attempt, which may be a bit simplified, would be to
substitute
> any newline, which occured at the end of a line which was preceeded by
2
> consecutive newlines, with a space. This relies on the format of the
> file being as shown for every company. It also may miss the first
> company in the file if the file doesn't start with a blank line.
>
> So
>
> undef $/;
> $file = ;
> $file =~ s/(\n\n.+?)\n/$1 /g;
> print $file;
>
> [untested]
>
> HTH
> Nigel
>
> >>> [EMAIL PROTECTED] 07/03/02 10:52pm >>>
> Hi  All,
>
> I am new to Perl and need help to solve this one !
>
> I have a txt file and the contents of the file are as below  :
>
> ---CONTENTS   OF   TEXT   FILE--
> Abdullah Ahmed Hassan
> Trading
> Location Ruwi Souk St, Ruwi
> Bus Hrs 0930-1300:1630-2200
> P.O. Box 197 Ruwi Code 112
> Phone 708940
> Fax 794156
> Key Staff Abdullah Ahmed Hassan
> Mohammad Hussain Ahmed Hassan
> Irfan Ahmed
> Mohammad Asim
> Activities :3410
> Email : [EMAIL PROTECTED]
>
> Abu Ali Trading & Cont
> Est
> Location Azaiba
> B us H rs 0700-1200; 1500-1900
> P.O. Box 1695 C. P. 0. Code 111
> Phone 595324
> Key Staff K. Sasi, Prop
> Ali Suleiman Al Ghubshi, Sponsor
> Activities 2700
>
> Abu Al Dahab Trading & Contg
> Est
> Location 23rd July St, Opp Al Ghobish
> Furniture Showroom
> Bus Hrs 0800-1300 (Sat-Thu); 1600-1900 (Sat-
> Fri)
> P.O. Box 1254 Salalah Code 211
> Phone 297879
> Fax 297879
> Key Staff Syed Tajudeen Madani, Gen Mgr
> Activities 2660
> ---CONTENTS  OF TEXT FILE--
>
> The names of three companies as above are:
>
> Abdullah Ahmed Hassan
> Trading
>
> Abu Ali Trading & Cont
> Est
>
> Abu Al Dahab Trading & Contg
> Est
>
> I want the data this way .
>
> ---DATA WANTED THIS WAY
> Abdullah Ahmed Hassan Trading
> Location Ruwi Souk St, Ruwi
> Bus Hrs 0930-1300:1630-2200
> P.O. Box 197 Ruwi Code 112
> Phone 708940
> Fax 794156
> Key Staff Abdullah Ahmed Hassan
> Mohammad Hussain Ahmed Hassan
> Irfan Ahmed
> Mohammad Asim
> Activities :3410
> Email : [EMAIL PROTECTED]
>
> Abu Ali Trading & Cont Est
> Location Azaiba
> B us H rs 0700-1200; 1500-1900
> P.O. Box 1695 C. P. 0. Code 111
> Phone 595324
> Key Staff K. Sasi, Prop
> Ali Suleiman Al Ghubshi, Sponsor
> Activities 2700
>
> Abu Al Dahab Trading & Contg Est
> Location 23rd July St, Opp Al Ghobish
> Furniture Showroom
> Bus Hrs 0800-1300 (Sat-Thu); 1600-1900 (Sat-
> Fri)
> P.O. Box 1254 Salalah Code 211
> Phone 297879
> Fax 297879
> Key Staff Syed Tajudeen Madani, Gen Mgr
> Activities 2660
> ---DATA WANTED THIS WAY
>
> I want PERL to make the name of the company to come in
> one line as it has done for all three records.
>
> I request your help solving this.
>
> Regards
>
> Sunish Kapoor
>
> ITM Business Solutions
> Unit 4
> Nine Trees Trading Estate
> Morthen Road
> Rotherham
> S66 9JG
>
> Reception
> Tel: 01709 703288
> Fax: 01709 701549
>
> Help Desk
> Tel:01709 530424
> Fax: 01709 702159
>
> CONFIDENTIALITY NOTICE: This message is intended only for the use of
> the individual or entity to which it is addressed, and may contain
> information that is privileged, confidential and exempt from
disclosure
> under applicable law.
>
> --
> 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]

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




Re: Regular Expression Help sought

2002-07-03 Thread Sunish Kapoor


Dear Nigel,

Thanks a ton for the script..It works fine though it skips the first record
even though I make
the file begin with a blank line by simply hitting enter !

Regards

Sunish
Nigel Peck wrote:

> My first attempt, which may be a bit simplified, would be to substitute
> any newline, which occured at the end of a line which was preceeded by 2
> consecutive newlines, with a space. This relies on the format of the
> file being as shown for every company. It also may miss the first
> company in the file if the file doesn't start with a blank line.
>
> So
>
> undef $/;
> $file = ;
> $file =~ s/(\n\n.+?)\n/$1 /g;
> print $file;
>
> [untested]
>
> HTH
> Nigel
>
> >>> [EMAIL PROTECTED] 07/03/02 10:52pm >>>
> Hi  All,
>
> I am new to Perl and need help to solve this one !
>
> I have a txt file and the contents of the file are as below  :
>
> ---CONTENTS   OF   TEXT   FILE--
> Abdullah Ahmed Hassan
> Trading
> Location Ruwi Souk St, Ruwi
> Bus Hrs 0930-1300:1630-2200
> P.O. Box 197 Ruwi Code 112
> Phone 708940
> Fax 794156
> Key Staff Abdullah Ahmed Hassan
> Mohammad Hussain Ahmed Hassan
> Irfan Ahmed
> Mohammad Asim
> Activities :3410
> Email : [EMAIL PROTECTED]
>
> Abu Ali Trading & Cont
> Est
> Location Azaiba
> B us H rs 0700-1200; 1500-1900
> P.O. Box 1695 C. P. 0. Code 111
> Phone 595324
> Key Staff K. Sasi, Prop
> Ali Suleiman Al Ghubshi, Sponsor
> Activities 2700
>
> Abu Al Dahab Trading & Contg
> Est
> Location 23rd July St, Opp Al Ghobish
> Furniture Showroom
> Bus Hrs 0800-1300 (Sat-Thu); 1600-1900 (Sat-
> Fri)
> P.O. Box 1254 Salalah Code 211
> Phone 297879
> Fax 297879
> Key Staff Syed Tajudeen Madani, Gen Mgr
> Activities 2660
> ---CONTENTS  OF TEXT FILE--
>
> The names of three companies as above are:
>
> Abdullah Ahmed Hassan
> Trading
>
> Abu Ali Trading & Cont
> Est
>
> Abu Al Dahab Trading & Contg
> Est
>
> I want the data this way .
>
> ---DATA WANTED THIS WAY
> Abdullah Ahmed Hassan Trading
> Location Ruwi Souk St, Ruwi
> Bus Hrs 0930-1300:1630-2200
> P.O. Box 197 Ruwi Code 112
> Phone 708940
> Fax 794156
> Key Staff Abdullah Ahmed Hassan
> Mohammad Hussain Ahmed Hassan
> Irfan Ahmed
> Mohammad Asim
> Activities :3410
> Email : [EMAIL PROTECTED]
>
> Abu Ali Trading & Cont Est
> Location Azaiba
> B us H rs 0700-1200; 1500-1900
> P.O. Box 1695 C. P. 0. Code 111
> Phone 595324
> Key Staff K. Sasi, Prop
> Ali Suleiman Al Ghubshi, Sponsor
> Activities 2700
>
> Abu Al Dahab Trading & Contg Est
> Location 23rd July St, Opp Al Ghobish
> Furniture Showroom
> Bus Hrs 0800-1300 (Sat-Thu); 1600-1900 (Sat-
> Fri)
> P.O. Box 1254 Salalah Code 211
> Phone 297879
> Fax 297879
> Key Staff Syed Tajudeen Madani, Gen Mgr
> Activities 2660
> ---DATA WANTED THIS WAY
>
> I want PERL to make the name of the company to come in
> one line as it has done for all three records.
>
> I request your help solving this.
>
> Regards
>
> Sunish Kapoor
>
> ITM Business Solutions
> Unit 4
> Nine Trees Trading Estate
> Morthen Road
> Rotherham
> S66 9JG
>
> Reception
> Tel: 01709 703288
> Fax: 01709 701549
>
> Help Desk
> Tel:01709 530424
> Fax: 01709 702159
>
> CONFIDENTIALITY NOTICE: This message is intended only for the use of
> the individual or entity to which it is addressed, and may contain
> information that is privileged, confidential and exempt from disclosure
> under applicable law.
>
> --
> 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: Regular Expression Help

2002-02-05 Thread Jeff 'japhy' Pinyan

On Feb 5, John W. Krahn said:

>Jeff 'Japhy' Pinyan wrote:
>> 
>>   $text =~ m{(<.*?>|&.*?;|{\$.*?}|<.*?=)|A}{$1 || "X"}seg;
> ^
> ^
> s

Sorry, thanks for the correction. :)

-- 
Jeff "japhy" Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
 what does y/// stand for?   why, yansliterate of course.


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




Re: Regular Expression Help

2002-02-05 Thread John W. Krahn

Jeff 'Japhy' Pinyan wrote:
> 
> On Feb 5, David Mamanakis said:
> >
> >I am building a parsing routine, and am using a regular expression, which
> >works, EXCEPT when I need to EXCLUDE certain things...
> >
> >$right =~ s/A/X/g;
> >
> >However, I may need to exclude this replacement in some of the values of
> >$right...
> >
> >Anything found between < and > SHOULD NOT be replaced.  \<.*\>
> >Anything found between & and ; SHOULD NOT be replaced.  \&.*\;
> >Anything found between {$ and } SHOULD NOT be replaced.  \{$.*\}
> >Anything found between < and = SHOULD NOT be replaced.  \<.*\=
> 
> Here's a crafty trick (from DALnet #perl a couple of minutes ago)...
> 
>   $text =~ m{(<.*?>|&.*?;|{\$.*?}|<.*?=)|A}{$1 || "X"}seg;
 ^
 ^
 s


> Basically, if it's a special case, it's matched and put in $1, and if it's
> "A", it's matched but $1 is undefined.  Then, on the right-hand side, we
> use $1 if it has a value, and "X" otherwise.
> 
> The /s is so that . matches newlines, the /e is so that $1 || "X" is
> evaluated as code, and the /g is for all matches.
> 
> It kinda sounds like you're working with HTML and some template thing,
> though... you might want to use a full HTML parser instead.



John
-- 
use Perl;
program
fulfillment

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




Re: Regular Expression Help

2002-02-05 Thread Jeff 'japhy' Pinyan

On Feb 5, David Mamanakis said:

>I am building a parsing routine, and am using a regular expression, which
>works, EXCEPT when I need to EXCLUDE certain things...
>
>$right =~ s/A/X/g;
>
>However, I may need to exclude this replacement in some of the values of
>$right...
>
>Anything found between < and > SHOULD NOT be replaced.  \<.*\>
>Anything found between & and ; SHOULD NOT be replaced.  \&.*\;
>Anything found between {$ and } SHOULD NOT be replaced.  \{$.*\}
>Anything found between < and = SHOULD NOT be replaced.  \<.*\=

Here's a crafty trick (from DALnet #perl a couple of minutes ago)...

  $text =~ m{(<.*?>|&.*?;|{\$.*?}|<.*?=)|A}{$1 || "X"}seg;

Basically, if it's a special case, it's matched and put in $1, and if it's
"A", it's matched but $1 is undefined.  Then, on the right-hand side, we
use $1 if it has a value, and "X" otherwise.

The /s is so that . matches newlines, the /e is so that $1 || "X" is
evaluated as code, and the /g is for all matches.

It kinda sounds like you're working with HTML and some template thing,
though... you might want to use a full HTML parser instead.

-- 
Jeff "japhy" Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
 what does y/// stand for?   why, yansliterate of course.


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




RE: regular expression help

2002-01-22 Thread Jonathan E. Paton


> | Hello!
> | 
> | If I have this line ROXETTE_PC_SW_R1D08 (locked)
> | and just want to remove the (locked) part from it
> | with an regexp how would that look?
> | 
> | I can do: s/(locked)// that leaves the  pesky () how
> | can I get rid off those?
>
> Try:
> 
>   s/\s+\(locked\)//
> 
> The parens are meta-symbols in regexes and need to be
> escaped if you want to match them. The above will
> additionally make sure that the blanks before (locked)
> are also removed.

Hi,

The input looks something like:

ROXETTE_PC_SW_R1D08 (locked)

you *might* consider just taking the leftmost characters. 
In a regex that'd look like:

my ($symbol) = /^(\w*)/;

Jonathan Paton 

__
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: regular expression help

2002-01-22 Thread marcus_holland-moritz

Try:

  s/\s+\(locked\)//

The parens are meta-symbols in regexes and need to be escaped
if you want to match them. The above will additionally make
sure that the blanks before (locked) are also removed.

HTH,
Marcus

| -Original Message-
| From: David Samuelsson (PAC) [mailto:[EMAIL PROTECTED]]
| Sent: Tuesday, January 22, 2002 10:37 AM
| To: '[EMAIL PROTECTED]'
| Subject: regular expression help
| 
| 
| Hello!
| 
| if i have this line ROXETTE_PC_SW_R1D08 (locked)
| 
| and just want to remove the (locked) part from it with an 
| regexp how would that look?
| 
| i can do: s/(locked)// that leaves the  pesky () how can i 
| get rid off those?
| 
| //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: regular expression help

2002-01-22 Thread John Edwards

Escape the brackets like so.

s/\(locked\)//;

John

-Original Message-
From: David Samuelsson (PAC) [mailto:[EMAIL PROTECTED]]
Sent: 22 January 2002 09:37
To: '[EMAIL PROTECTED]'
Subject: regular expression help


Hello!

if i have this line ROXETTE_PC_SW_R1D08 (locked)

and just want to remove the (locked) part from it with an regexp how would
that look?

i can do: s/(locked)// that leaves the  pesky () how can i get rid off
those?

//Dave




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


--Confidentiality--.
This E-mail is confidential.  It should not be read, copied, disclosed or
used by any person other than the intended recipient.  Unauthorised use,
disclosure or copying by whatever medium is strictly prohibited and may be
unlawful.  If you have received this E-mail in error please contact the
sender immediately and delete the E-mail from your system.



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




RE: Regular expression help!!

2001-10-28 Thread Veeraraju_Mareddi

Hi Warren
Just Look at it.

$str= 'insert_job: DUKS_rtcf_daily_log_purge job_type: c';
$str =~ s/[^:]*://;

With Regards
Raju



--
From:  Woz [SMTP:[EMAIL PROTECTED]]
Sent:  Thursday, October 25, 2001 3:34 PM
To:  [EMAIL PROTECTED]; [EMAIL PROTECTED]
Subject:  RE: Regular expression help!!

Wow, that was fast!
 
Thanks very much, that works well.
For my next question (:-)) how can I make it strip the leading space
that it leaves on the resulting string. i.e. I want it to strip
'insert_job: ' from the string - note the trailing space.
 
At the moment I have: -
 
  ($Value)=$_=~m/(\W\w\S.*)/; 
  ($Value)=$Value=~m/(\S.*)/;
 
but I'm sure there's a far more elegant solution that combines it
all
into one.
 
Many many thanks for your help.
 
Warren



-Original Message- 
From: Robert Graham 
Sent: Thu 25/10/2001 10:27 
To: Woz; [EMAIL PROTECTED] 
Cc: 
    Subject: RE: Regular expression help!!



Hi 

You can try the following: 

$line = "insert_job: DUKS_rtcf_daily_log_purge job_type: c";

($rest) = $line =~ m/(\W\w.*)/; 


Regards 
Robert 

-Original Message- 
From: Woz [mailto:[EMAIL PROTECTED]] 
Sent: 25 October 2001 11:17 
To: [EMAIL PROTECTED] 
Subject: Regular expression help!! 


Hi, 
  
I'm relatively new to the wonders of Perl programming and
I've
yet to 
quite get my head around regular expressions. 
I'm attempting to generate a search and replace expression
that
will 
turn the following string 
  
insert_job: DUKS_rtcf_daily_log_purge job_type: c 
  
into 
  
DUKS_rtcf_daily_log_purge job_type: c 
  
i.e. remove from the beginning of the line up the space
following the 
first : 
All my efforts so far remove upto the second : though and
leave
just 
'c'. 
  
Any ideas? 
  
Any help much appreciated! 
  
Thanks, 
  
Warren 
  
<>

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




RE: Regular expression help!!

2001-10-25 Thread Woz

Many thanks for the help Robert, those pointers were enough to give me a
kickstart in the right direction and everything is working perfectly
now! :-)
 
Cheers,
 
Woz
 

-Original Message- 
From: Robert Graham 
Sent: Thu 25/10/2001 11:19 
To: Woz; [EMAIL PROTECTED] 
Cc: 
Subject: RE: Regular expression help!!


You can use the following to remove the space in front
$Value =~ /s/^\s+//;
 
And for the sake of interest $Value =~ s/\s+$//; will remove any
trailing spaces from a string
 
Regards
Robert Graham

-Original Message-
From: Woz [mailto:[EMAIL PROTECTED]]
Sent: 25 October 2001 12:04
To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
Subject: RE: Regular expression help!!


Wow, that was fast!
 
Thanks very much, that works well.
For my next question (:-)) how can I make it strip the
leading space that it leaves on the resulting string. i.e. I want it to
strip 'insert_job: ' from the string - note the trailing space.
 
At the moment I have: -
 
  ($Value)=$_=~m/(\W\w\S.*)/; 
  ($Value)=$Value=~m/(\S.*)/;
 
but I'm sure there's a far more elegant solution that
combines it all into one.
 
Many many thanks for your help.
 
Warren



-Original Message- 
From: Robert Graham 
Sent: Thu 25/10/2001 10:27 
To: Woz; [EMAIL PROTECTED] 
Cc: 
        Subject: RE: Regular expression help!!



Hi 

You can try the following: 

$line = "insert_job: DUKS_rtcf_daily_log_purge
job_type: c"; 
($rest) = $line =~ m/(\W\w.*)/; 


Regards 
Robert 

-Original Message- 
From: Woz [mailto:[EMAIL PROTECTED]] 
Sent: 25 October 2001 11:17 
To: [EMAIL PROTECTED] 
Subject: Regular expression help!! 


Hi, 
  
I'm relatively new to the wonders of Perl
programming and I've yet to 
quite get my head around regular expressions. 
I'm attempting to generate a search and replace
expression that will 
turn the following string 
  
insert_job: DUKS_rtcf_daily_log_purge job_type:
c 
  
into 
  
DUKS_rtcf_daily_log_purge job_type: c 
  
i.e. remove from the beginning of the line up
the space following the 
first : 
All my efforts so far remove upto the second :
though and leave just 
'c'. 
  
Any ideas? 
  
Any help much appreciated! 
  
Thanks, 
  
Warren 
  



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


Re: Regular expression help!!

2001-10-25 Thread Jeff 'japhy' Pinyan

On Oct 25, Woz said:

>turn the following string
> 
>insert_job: DUKS_rtcf_daily_log_purge job_type: c
> 
>into
> 
>DUKS_rtcf_daily_log_purge job_type: c
> 
>i.e. remove from the beginning of the line up the space following the
>first :

You're probably trying

  s/.*: //;

which is matching greedily all the way to the last : it finds.  There are
two approaches you can take to fix this:

  s/.*?: //;# non-greedy matching stops as soon as possible
  s/[^:]*: //;  # match zero or more non-colons

-- 
Jeff "japhy" Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **


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




RE: Regular expression help!!

2001-10-25 Thread Robert Graham

You can use the following to remove the space in front
$Value =~ /s/^\s+//;
 
And for the sake of interest $Value =~ s/\s+$//; will remove any trailing
spaces from a string
 
Regards
Robert Graham

-Original Message-
From: Woz [mailto:[EMAIL PROTECTED]]
Sent: 25 October 2001 12:04
To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
Subject: RE: Regular expression help!!


Wow, that was fast!
 
Thanks very much, that works well.
For my next question (:-)) how can I make it strip the leading space that it
leaves on the resulting string. i.e. I want it to strip 'insert_job: ' from
the string - note the trailing space.
 
At the moment I have: -
 
  ($Value)=$_=~m/(\W\w\S.*)/; 
  ($Value)=$Value=~m/(\S.*)/;
 
but I'm sure there's a far more elegant solution that combines it all into
one.
 
Many many thanks for your help.
 
Warren



-Original Message- 
From: Robert Graham 
Sent: Thu 25/10/2001 10:27 
To: Woz; [EMAIL PROTECTED] 
Cc: 
Subject: RE: Regular expression help!!



Hi 

You can try the following: 

$line = "insert_job: DUKS_rtcf_daily_log_purge job_type: c"; 
($rest) = $line =~ m/(\W\w.*)/; 


Regards 
Robert 

-Original Message- 
From: Woz [ mailto:[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]> ] 
Sent: 25 October 2001 11:17 
To: [EMAIL PROTECTED] 
Subject: Regular expression help!! 


Hi, 
  
I'm relatively new to the wonders of Perl programming and I've yet to 
quite get my head around regular expressions. 
I'm attempting to generate a search and replace expression that will 
turn the following string 
  
insert_job: DUKS_rtcf_daily_log_purge job_type: c 
  
into 
  
DUKS_rtcf_daily_log_purge job_type: c 
  
i.e. remove from the beginning of the line up the space following the 
first : 
All my efforts so far remove upto the second : though and leave just 
'c'. 
  
Any ideas? 
  
Any help much appreciated! 
  
Thanks, 
  
Warren 
  




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


RE: Regular expression help!!

2001-10-25 Thread Woz

Wow, that was fast!
 
Thanks very much, that works well.
For my next question (:-)) how can I make it strip the leading space
that it leaves on the resulting string. i.e. I want it to strip
'insert_job: ' from the string - note the trailing space.
 
At the moment I have: -
 
  ($Value)=$_=~m/(\W\w\S.*)/; 
  ($Value)=$Value=~m/(\S.*)/;
 
but I'm sure there's a far more elegant solution that combines it all
into one.
 
Many many thanks for your help.
 
Warren



-Original Message- 
From: Robert Graham 
Sent: Thu 25/10/2001 10:27 
To: Woz; [EMAIL PROTECTED] 
Cc: 
    Subject: RE: Regular expression help!!



Hi 

You can try the following: 

$line = "insert_job: DUKS_rtcf_daily_log_purge job_type: c"; 
($rest) = $line =~ m/(\W\w.*)/; 


Regards 
Robert 

-Original Message- 
From: Woz [mailto:[EMAIL PROTECTED]] 
Sent: 25 October 2001 11:17 
To: [EMAIL PROTECTED] 
Subject: Regular expression help!! 


Hi, 
  
I'm relatively new to the wonders of Perl programming and I've
yet to 
quite get my head around regular expressions. 
I'm attempting to generate a search and replace expression that
will 
turn the following string 
  
insert_job: DUKS_rtcf_daily_log_purge job_type: c 
  
into 
  
DUKS_rtcf_daily_log_purge job_type: c 
  
i.e. remove from the beginning of the line up the space
following the 
first : 
All my efforts so far remove upto the second : though and leave
just 
'c'. 
  
Any ideas? 
  
Any help much appreciated! 
  
Thanks, 
  
Warren 
  



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


RE: Regular expression help!!

2001-10-25 Thread Robert Graham

Hi

You can try the following:

$line = "insert_job: DUKS_rtcf_daily_log_purge job_type: c";
($rest) = $line =~ m/(\W\w.*)/;


Regards
Robert

-Original Message-
From: Woz [mailto:[EMAIL PROTECTED]]
Sent: 25 October 2001 11:17
To: [EMAIL PROTECTED]
Subject: Regular expression help!!


Hi,
 
I'm relatively new to the wonders of Perl programming and I've yet to
quite get my head around regular expressions.
I'm attempting to generate a search and replace expression that will
turn the following string
 
insert_job: DUKS_rtcf_daily_log_purge job_type: c
 
into
 
DUKS_rtcf_daily_log_purge job_type: c
 
i.e. remove from the beginning of the line up the space following the
first :
All my efforts so far remove upto the second : though and leave just
'c'.
 
Any ideas?
 
Any help much appreciated!
 
Thanks,
 
Warren
 



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


Re: Regular Expression Help

2001-10-19 Thread Randal L. Schwartz

> "Stephan" == Stephan Gross <[EMAIL PROTECTED]> writes:

Stephan> I'm matching a SQL date like this:
Stephan>$ftime =~ /(\d+)-(\d+)-(\d+)\s+(\d+):(\d+):(\d+)/;
 
Stephan> If $ftime is "2001-05-13 11:53:00", then $1 is "2001", $2 is "05", etc.
 
Stephan> However, I also want to match if the user types in a partial string.  For
Stephan> example, if $ftime is "2001-12-18", I want $1, $2 and $3 to be "2001", "12"
Stephan> and "18" but $4 to be null.  In reality, my regex fails entirely and $1 is
Stephan> null.
 
Stephan> How can I get $1, $2, $3, $4, $5 and $6 to contain as many matches as my
Stephan> input string has?  Do I have to use 6 separate regexes?


if (my @matches = grep defined, $ftime =~ 
/(\d+)(?:-(\d+)(?:-(\d+)(?:\s+(\d+)(?::(\d+)(?::(\d+))?)?)?)?)?/) {

   ... $matches[0]..$matches[6] are now set as many as are defined...
}

Your first example was broken in that you weren't testing the overall
match, and if that had failed, you would have gotten the *previous* match.
Bad News.


-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[EMAIL PROTECTED]> http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

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