Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > reg expr, extract digit from string.

Reply
Thread Tools

reg expr, extract digit from string.

 
 
joel
Guest
Posts: n/a
 
      03-18-2005
Hi,

I need help with extracting digit from a string.

example:

here is the string i want to split into words and digits.

my $string = "abcd-efgh-ijkl-123.456.789"

i want

$word = "abcd-efgh-ijkl";

and

$digit = "123.456.789";



Thanks in advance,

Joel
 
Reply With Quote
 
 
 
 
phaylon
Guest
Posts: n/a
 
      03-18-2005
joel wrote:

> i want


What have you tried?

--
http://www.dunkelheit.at/

»Better to reign in hell than to serve in heaven«
-- John Milton, »Paradise Lost«

 
Reply With Quote
 
 
 
 
Arndt Jonasson
Guest
Posts: n/a
 
      03-18-2005

http://www.velocityreviews.com/forums/(E-Mail Removed) (joel) writes:
>
> I need help with extracting digit from a string.
>
> example:
>
> here is the string i want to split into words and digits.
>
> my $string = "abcd-efgh-ijkl-123.456.789"
>
> i want
>
> $word = "abcd-efgh-ijkl";
>
> and
>
> $digit = "123.456.789";


You seem to have split it successfully yourself already. What's the
general pattern for your string and word/digit parts? Does the
digit part contain only digits and periods, and the word part only
letters and hyphens?
 
Reply With Quote
 
Tad McClellan
Guest
Posts: n/a
 
      03-18-2005
joel <(E-Mail Removed)> wrote:


> my $string = "abcd-efgh-ijkl-123.456.789"
> i want
> $word = "abcd-efgh-ijkl";
> and
> $digit = "123.456.789";



my($word, $digit) = $string =~ /(.*)-(.*)/;


--
Tad McClellan SGML consulting
(E-Mail Removed) Perl programming
Fort Worth, Texas
 
Reply With Quote
 
John W. Krahn
Guest
Posts: n/a
 
      03-18-2005
joel wrote:
>
> I need help with extracting digit from a string.
>
> example:
>
> here is the string i want to split into words and digits.
>
> my $string = "abcd-efgh-ijkl-123.456.789"
>
> i want
>
> $word = "abcd-efgh-ijkl";
>
> and
>
> $digit = "123.456.789";


$ perl -le'
my $string = "abcd-efgh-ijkl-123.456.789";
my ( $word, $digit ) = split /(?<=\D)-(?=\d)/, $string, 2;
print for $word, $digit;
'
abcd-efgh-ijkl
123.456.789



John
--
use Perl;
program
fulfillment
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
(8-bit binary to two digit bcd) or (8-bit binary to two digit seven segment) Fangs VHDL 3 10-26-2008 06:41 AM
How do i extract vidios when winrar wont extract them??? help plzzzzzzzz smuttdog@sc.rr.com Computer Support 2 12-23-2007 07:03 AM
reg expr, extract word from string joelix@gmail.com Perl Misc 6 10-07-2005 07:21 PM
Windows Reg Pro vs Tweak now Reg Cleaner vs Registry fix, vs RegCleaner jl Computer Support 3 05-31-2005 12:53 AM
match three digit number using regular expression championsleeper Perl 6 04-06-2004 08:54 PM



Advertisments