|
|
|
| Hi,
I've a plain text file with something like this
313 121 3
sdsfa
ASDASD
ab.something
123123
213121
12313
ab.something
sdf weef w
vdsv ds2
and so on
I'd like to put the "ab.something" in a $var so I write this
$var =~ /^(var\.){1}.[a-z]/;
print "\n\n\n$var\n\n\n";
but it's wrong
I'm sorry but this is my first reg exp.
Could someone help me? thanks a lot
--
Umin
n. p.: U2 - New Year's Day
| |
|
| Umin ha detto questo giovedì :
> Hi,
> I've a plain text file with something like this
> 313 121 3
> sdsfa
> ASDASD
> ab.something
[...] CUT
ok, i made it
$var =~ /((ab\.){1}\D+)/;
print "\n\n\n$1\n\n\n";
--
Umin
n. p.: U2 - Drowning Man
| |
| Matt Garrish 2006-02-09, 6:58 pm |
|
"Umin" <alias2k@libero.it> wrote in message
news:mn.4bb47d62c7ff251d.32213@libero.it...
> Umin ha detto questo giovedì :
>
> [...] CUT
>
> ok, i made it
>
> $var =~ /((ab\.){1}\D+)/;
That's a pretty bad regular expression. There's no need to specify {1}, it's
assumed by default. There's also no need to subcapture the 'ab.', since your
first parens capture it anyway and you're not doing anything with it. You
should also check whether the match succeeds before trying to use $1:
if ($var =~ /(ab\.\D+)/) {
print "$1\n";
}
Matt
| |
|
| Matt Garrish ci ha detto :
> That's a pretty bad regular expression. There's no need to specify {1}, it's
> assumed by default. There's also no need to subcapture the 'ab.', since your
> first parens capture it anyway and you're not doing anything with it. You
> should also check whether the match succeeds before trying to use $1:
> if ($var =~ /(ab\.\D+)/) {
> print "$1\n";
> }
ok! thanks a lot
I was following the sample on the manual but I was sure to make some
mistake.
I've to study!
:)
--
Umin
n. p.: Gathering - When the Sun Hits (Slowdive Cover Version)
| |
| Matt Garrish 2006-02-09, 9:55 pm |
|
"Umin" <alias2k@libero.it> wrote in message
news:mn.50297d625cbbc6c6.32213@libero.it...
> Matt Garrish ci ha detto :
>
>
>
> ok! thanks a lot
> I was following the sample on the manual but I was sure to make some
> mistake.
> I've to study!
> :)
>
Perlretut (http://perldoc.perl.org/perlretut.html) is a good document for
getting started (perlre has the nuts and bolts, but is more for the advanced
user). Mastering Regular Expressions is also a very good book to read if you
can get your hands on a copy, but more for the theory and best practices
than for getting started and using them in Perl.
Matt
|
|
|
|