Solved

remove number in text

Posted on 2003-11-06
15
197 Views
Last Modified: 2010-03-04
$fields[12] =~ s/\s+0\d+//g;

This works to remove th number begins with 0 in context.
However it does not work in the cases belows
TEL:040/72105730 : if some signs before 0, it dows not work
0998-20344 in this case
(040-2093494) In this case also?
Could you please make it work?
0
Comment
Question by:tilmes
  • 8
  • 3
  • 2
  • +1
15 Comments
 
LVL 3

Expert Comment

by:prady_21
ID: 9699534
$fields[12] =~ s/\s+0[\d-\/]+//g;
0
 
LVL 3

Expert Comment

by:prady_21
ID: 9699537
the above one wont work, sorry

$fields[12] =~ s/\s+0[-\d\/]+//g;
0
 

Author Comment

by:tilmes
ID: 9699619
Hello

it does not work. this Tel:0174 and Tel.0190 shows still in view
0
 

Author Comment

by:tilmes
ID: 9699645
Can this work, if some signs before 0 wrote, for exmpale :0174
it shows still. Can remove all the numbers begins with 0
both either in case begins direct with 0 or some signs is already before 0?
0
 
LVL 20

Expert Comment

by:jmcg
ID: 9699689
I'm a little leery of blindly removing leading zeroes, but if you define a leading zero as any one of a sequence of one or more zeroes that follow a nondigit and precede a digit, then maybe this regular expression substitution will do what you ask:

$fields[12] =~ s/(^|\D)0+(\d)/$1$2/g;
0
 

Author Comment

by:tilmes
ID: 9699720
This one removes only 0, the digit follows remained.
e.g. 04213444 becomes 4213444
0
 

Author Comment

by:tilmes
ID: 9699749
Maybe it would be better if
the text begins with "Tel." or "Tel:" or "(0" remove following all digits.
and remove whole numbers begins with 0
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:tilmes
ID: 9699813
I am sorry,
It is firm if this works
remove all digits begins with 0
remove all digits include ":0" or ".0"
0
 
LVL 20

Expert Comment

by:jmcg
ID: 9699906
Perhaps you need to start at the beginning. What is it you are trying to do? Please take the time to explain it clearly, since we are currently just making stabs in the dark.
0
 
LVL 3

Expert Comment

by:BioI
ID: 9700005
another stab in the dark :-)  If you want to delete only the prefix e.g. TEL:040/72105730 has to become TEL:72105730 you can use the following:
$fields[12]=~ s/(^|\D)0+\d*\D{0,1}(\d*)/$1$2/g;

the outputs:
 TEL:040/72105730  => TEL:72105730
 0998-20344 => 20344
 (040-2093494) => (2093494)
 099820344 =>                 (empty)

So according to jmcg's question: what is correct of these substitions and what isn't correct?
0
 

Author Comment

by:tilmes
ID: 9700041
can it be this way?
the outputs:
 TEL:040/72105730  => TEL:(empty)
 0998-20344 => (empty)
 (040-2093494) => ((empty))
 099820344 =>                 (empty)
0
 
LVL 3

Accepted Solution

by:
BioI earned 100 total points
ID: 9700076
This one works for all the cases [maybe not the most elegant way? experts, correct me when i am wrong]
$word =~ s/(^|\D)0+\d*\D{0,1}\d*/$1/g;
0
 

Author Comment

by:tilmes
ID: 9700105
Hi BioI,

It works very good,
thanks again.
0
 
LVL 3

Expert Comment

by:BioI
ID: 9700210
Hi Tilmes,

Nice that it works!  
But do you sometimes consider to split points?  Because in this case, I just proceeded the work of the experts above [in fact on the solution proposed by jmcg].  Maybe it's worth considering this next time...
CU around!
0
 

Author Comment

by:tilmes
ID: 9702641
Dear Bios

thanks for the advice. I know now how it works and it will be fair next time.
CU around!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Perl output collect 7 65
Using Perl DBI to query oracle 3 33
How to generate square thumbnail using perl 13 77
How to translate this 2-line while loop into C from Perl? 8 74
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now