Re: how to extract digit from a line in Perl

2004-07-14 Thread David Dorward
On 14 Jul 2004, at 11:00, Franklin wrote:
I want to extract the digit from a line of text. For exmple, for a 
text line: TSC2101Net, how can I write a script to extract 2101 and 
print it?
There are number of techniques that spring to mind, the obvious being 
regular expressions and substring. The latter isn't much good unless 
you know the position of the numbers in the string. The former is more 
flexible but also more complex.

perldoc perlrequick
perldoc -f substr
  IncrediMail - Email has finally evolved - Click Here
Evolved into a distracting blinking thing that gives me a headache. 
Eugh.

--
David Dorward
 

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



RE: how to extract digit from a line in Perl

2004-07-14 Thread NYIMI Jose (BMB)
Title: Message



 

  
  -Original Message-From: Franklin 
  [mailto:[EMAIL PROTECTED] Sent: Wednesday, July 14, 2004 12:01 
  PMTo: [EMAIL PROTECTED]Subject: how to extract digit 
  from a line in Perl
  

  
Hello:
 
I want to extract the digit from a line of text. For exmple, for a 
text line: TSC2101Net, how can I write a script to extract 2101 and print it?
 
Thank you very much in advance!
 
Bestwishes
Franklin
 
 

  

  
  



    
  IncrediMail - Email has finally evolved - Click Here 
   
   
  If you are SURE that your digits are always between TSC and Net,
  You can do the following:
  my ($number)=$text=~/TSC(\d+)Net/;
  print "$number\n";
  HTH,
  José.

 DISCLAIMER 

"This e-mail and any attachment thereto may contain information which is confidential and/or protected by intellectual property rights and are intended for the sole use of the recipient(s) named above. 
Any use of the information contained herein (including, but not limited to, total or partial reproduction, communication or distribution in any form) by other persons than the designated recipient(s) is prohibited. 
If you have received this e-mail in error, please notify the sender either by telephone or by e-mail and delete the material from any computer".

Thank you for your cooperation.

For further information about Proximus mobile phone services please see our website at http://www.proximus.be or refer to any Proximus agent.




IMSTP.gif
Description: IMSTP.gif


Re: how to extract digit from a line in Perl

2004-07-14 Thread iko
Franklin wrote:

> Hello:
> I want to extract the digit from a line of text. For exmple, for a
> text line: TSC2101Net, how can I write a script to extract 2101 and
> print it?
> Thank you very much in advance!
> Bestwishes
> Franklin
>
>   
>   
>
> 
>  /IncrediMail/
> - *Email has finally evolved* - *_Click Here_*
> 

try this [take your own risk :) ] :

**cut here*
#!/usr/bin/perl
#

$bannerkoe=<;

foreach $bingung(@fh) {
@pecah=split/ /,$bingung;
foreach (@pecah) {
@kar=split//,$_;
foreach $elemen(@kar) {
$hasil=$elemen=~m/(\d+)/;
if ($hasil) {print "$elemen";}
}
}
print "\nasalnya : $bingung\n";
}

close(FH);
cut here**

the content of tes_regex2.txt :
aku tes aja ya...
TSC2101Net
:)



Iko Riyadi
Departemen Data Manajemen
PT. Infomedia Nusantara
Jl. Kusuma Bangsa 10-12
Surabaya 60272 Indonesia
Telp: +62 (031) 5326282, Fax: +62 (031) 5343613
http://www.yellowpages.co.id

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




RE: how to extract digit from a line in Perl

2004-07-14 Thread Bob Showalter
Franklin wrote:
> Hello:
> 
> I want to extract the digit from a line of text. For exmple, for a
> text line: TSC2101Net, how can I write a script to extract 2101 and
> print it?  

Use a regex to capture a series of digits:

  $_ = 'TSC2101Net';
  my ($num) = /(\d+)/;
  print "Found $num\n" if defined $num;

This will simply find the leftmost sequence of one or more digits in the
string.

HTH

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]