Re: Extract part of a string
- From: Paul Lalli <mritty@xxxxxxxxx>
- Date: 30 Apr 2007 14:10:24 -0700
On Apr 30, 2:47 pm, roopa...@xxxxxxxxx wrote:
On Apr 30, 9:53 am, Paul Lalli <mri...@xxxxxxxxx> wrote:
On Apr 30, 9:21 am, roopa...@xxxxxxxxx wrote:
Hi,
I want to extract everything between the hash signs in the following
string
"### This is a test ###"
I am using the following..
if($desc=~ /\#{3}(.*?)\#{3}/ )
{
print $1;
}
I am not getting the desired result. Please tell me what I am doing
wrong.
What you're doing wrong is not posting a short-but complete script
that demonstrates your error. Because what you have above *does*
work. So therefore you're doing something wrong in your actual code
that you haven't bothered to show us...
$ perl -e'
my $desc = "### This is a test ###";
if($desc=~ /\#{3}(.*?)\#{3}/ )
{
print $1;}
'
Results: This is a test
Paul Lalli- Hide quoted text -
- Show quoted text -
My String contains new line characters like
"This is a test
BEGIN PART INFORMATION##
5G5E-6010-AA|BLK ASY-CYL|
##END PART INFORMATION
"
And apparently your string also has only 2 # characters bunched
together, not three?
What part of "post a short but complete script" was too difficult to
follow? Why are you making me *guess* what other differences might be
in your real code, that you didn't feel like sharing with us? You're
being very rude to those people who are volunteering their time trying
to help you.
Read `perldoc perlretut` and `perldoc perlre`.
You need the /s modifier on your regexp to allow the . wildcard to
match newlines.
Paul Lalli
.
- References:
- Extract part of a string
- From: roopa . pd
- Re: Extract part of a string
- From: Paul Lalli
- Re: Extract part of a string
- From: roopa . pd
- Extract part of a string
- Prev by Date: Re: Mac::Carbon Bug
- Previous by thread: Re: Extract part of a string
- Next by thread: unit messages
- Index(es):
Relevant Pages
|