Hi,

It works fine and I like it. My regex is not that good, but I can see what
is doing. I modified it a bit (to capture up till a full stop sign).

<Code>
#!/usr/bin/perl
#
use strict;
use warnings;
#
my $str = "The black cat is trying to climbed the green tree. This time it
failed."; print "string: $str\n";
my $sbstr = substr $str, 0,17;
print "The substr function with length 17 will capture: $sbstr\n";
$str =~ m{ \A ( .{17} .*?\. ) \s }msx;
my $extracted = $1;
print "The pattern with quantifier set 17, extracted: $extracted\n"; <Code>
<Code>


Outputs:

string: The black cat is trying to climbed the green tree. This time it
failed.
The substr function with length 17 will capture: The black cat is
The pattern with quantifier set 17, extracted: The black cat is trying to
climbed the green tree.


Cool





-----Original Message-----
From: Akhthar Parvez K [mailto:akht...@sysadminguide.com] 
Sent: 18 April 2010 15:45
To: beginners@perl.org
Subject: Re: Extract substring from offset to space or full stop

Hi Shawn,

> $str =~ m{ \A ( .{15} .*? ) \s }msx;

I don't think this would work if the value given in the match string (15 as
per above eg.) is greater than the character count of the particular string.
Right?

Regards,
Akhthar Parvez K
http://Tips.SysAdminGUIDE.COM
UNIX is basically a simple operating system, but you have to be a genius to
understand the simplicity - Dennie Richie

On Sunday 18 Apr 2010, Shawn H Corey wrote:
> #!/usr/bin/perl
> 
> use strict;
> use warnings;
> 
> my $str = "The black cat climbed the green tree";
> print "string: $str\n";
> 
> my $extracted = $1;
> print "extracted: $extracted\n";



-- 
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/


Reply via email to