Re: Extract part of a string



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

.



Relevant Pages

  • Re: extracting inner key from a hash of hashes
    ... Paul Lalli wrote: ... Here is my hash structure. ... I was able to extract the distance portion like this. ... particular destination address. ...
    (comp.lang.perl.misc)
  • Re: array to string conversion
    ... # Assuming my hash: ... # I need to extract the values in each array with the extentions(values ... # periods) into another string. ...
    (comp.lang.ruby)
  • Please help with regexp - finding all matches?
    ... I'm trying to extract name:value pairs from a string similar to this one ... Ideally I want to just assign the result of the match to a hash. ...
    (comp.lang.perl)
  • Re: array to string conversion
    ... I now encounter another problem.. ... # I need to extract the values in each array with the extentions(values ... # periods) into another string. ... Assuming I have my hash: ...
    (comp.lang.ruby)
  • Re: HoHoH (hash of HoHs)
    ... >> I have a file that contains either a hash, or a HoH on each line. ... > A text file doesn't contain hashes, ... I extract them using the 'eval' function on ... > To collect the resulting hashes in another hash, you need a key (a string) ...
    (comp.lang.perl.misc)