Re: show only numbers before, within or after the text
- From: rob.dixon@xxxxxxx (Rob Dixon)
- Date: Sun, 29 Jun 2008 21:46:36 +0100
Luca Villa wrote:
I have a long text file like this:
324yellow
34house
black
54532
15m21red56
44dfdsf8sfd23
How can I obtain (Perl - Windows/commandline/singleline) the
following?
1) only the numbers at the beginning before some alpha text, like
this:
324
34
15
44
2) only the numbers within the alpha text, like this:
21
8
3) only the numbers at the end after some alpha text, like this:
56
23
Something like this?
HTH,
Rob
use strict;
use warnings;
my @data = qw/
324yellow
34house
black
54532
15m21red56
44dfdsf8sfd23
/;
foreach (@data) {
print "$_:\n";
while (/(^|\D)(\d+)/g) {
my $bef = not $1;
my $val = $2;
my $aft = not /(?=\D)/gc;
if ($bef) {
print "'$val' found before text\n" unless $aft;
}
elsif ($aft) {
print "'$val' found after text\n";
}
else {
print "'$val' found within text\n";
}
}
print "\n";
}
**OUTPUT**
324yellow:
'324' found before text
34house:
'34' found before text
black:
54532:
15m21red56:
'15' found before text
'21' found within text
'56' found after text
44dfdsf8sfd23:
'44' found before text
'8' found within text
'23' found after text
.
- References:
- show only numbers before, within or after the text
- From: Luca Villa
- show only numbers before, within or after the text
- Prev by Date: Re: show only numbers before, within or after the text
- Next by Date: Re: MIME::QuotedPrint - extra '=' and linebreak?
- Previous by thread: Re: show only numbers before, within or after the text
- Next by thread: MIME::QuotedPrint - extra '=' and linebreak?
- Index(es):
Relevant Pages
|