Re: extract variables from expression




"Matt Garrish" <matthew.garrish@xxxxxxxxxxxx> wrote in message
news:7pJ4g.4790$fx.440916@xxxxxxxxxxxxxxxxxxxxxxxx

<alexjaquet@xxxxxxxxx> wrote in message
news:1146314371.196741.78670@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hi,

Does somebody know how to extract some variables from this expression :

[quote=alexandre]Ceci est un testttttt[/quote]

I want to extract the values alexandre and the text "Ceci est un test"
and I can have multiple quoted expression :
[quote=alexandre]Ceci est un testttttt[/quote]
[quote=tester]response[/quote]


Assuming no nested quotes and the data is always as simple as the above:

while (my $line = <DATA>) {
if ($line =~ m#\[([^\]]+)](.*?)\[/quote]#) {
my $speaker = (split(/=/, $1))[1];

I was going somewhere else with that code. It can be made much simpler and
reliable for this single case with the following:

if ($line =~ m#\[quote=([^\]]+)](.*?)\[/quote]#) {
my $speaker = $1;

my $quote = $2;
}
}

__DATA__
[quote=alexandre]Ceci est un testttttt[/quote]
[quote=tester]response[/quote]





.



Relevant Pages

  • Re: extract variables from expression
    ... Does somebody know how to extract some variables from this expression: ... I want to extract the values alexandre and the text "Ceci est un test" ... Assuming no nested quotes and the data is always as simple as the above: ...
    (comp.lang.perl.misc)
  • extract variables from expression
    ... Does somebody know how to extract some variables from this expression: ... I want to extract the values alexandre and the text "Ceci est un test" ...
    (comp.lang.perl.misc)