Wrox Programmer Forums
|
BOOK: Beginning Regular Expressions
This is the forum to discuss the Wrox book Beginning Regular Expressions by Andrew Watt; ISBN: 9780764574894
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Regular Expressions section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 21st, 2005, 03:48 PM
Registered User
 
Join Date: Nov 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Regular Expressions Help Needed

Hello,
I'm trying this since a week and am not able to get the result. Would appreciate if anyone would help me out with this one.

The given input is in the form 123-45-6789

Using regular expressions i want to extract 123456789 wihout "-"s.

I used the belwo RE
(?(\w[A-Za-z]*))\d{3}\-\d{2}\-\d{4}

It returns 123-45-6789

Can any one suggest me a way to extract only the nine digits without the hypens.

Thank You very much.

 
Old November 21st, 2005, 04:00 PM
Registered User
 
Join Date: Nov 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Can anyone please help mw out with the above.
Thanks

 
Old May 31st, 2006, 05:18 AM
ufo ufo is offline
Authorized User
 
Join Date: Apr 2006
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

This will return you the three groups without hyphens:
(\d{3})-(\d{2})-(\d{4})

It will not do output formatting, because that's not what regex is meant for... so you will have to stick the pieces together yourself in the software you are writing, with a replace function...
 
Old September 8th, 2006, 03:04 AM
Registered User
 
Join Date: Sep 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Mak,

 I'm master of Perl regex. :-)
 This simple program explain, how to extract first sequense of exact nine digits from a string.
The found nine digits are not preceded or followed any digit.
 Sorry for my English (I studied German).

#!/usr/bin/perl -w
use strict;

my $s='012-34-56789 123-45-6789 012-34-5678';
my $result;
our $temp;
print "$result\n" if $s =~ /(?{local $temp=''})(?<!\d)(\d(?{$temp.=chr vec($s,pos($s)-1,8)})-?){9}(?![\d-])(?{$result=$temp})/;

# Output: 123456789


Regards,
Serge
http://www.gameintellect.com
 
Old January 29th, 2007, 04:35 PM
Registered User
 
Join Date: Jan 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

could u please help!!

I need regexp to match the string:

0123456789_abc_abc.xml

where as: _abc is optional.

My reg exp looks like:
String regExp = "^\\d{10}(_\\d)?(_\\d)?\\.xml$";

But it does not work correctly, any ideas please??

Thx

Simon



Quote:
quote:Originally posted by Serge314
 Hi Mak,

 I'm master of Perl regex. :-)
 This simple program explain, how to extract first sequense of exact nine digits from a string.
The found nine digits are not preceded or followed any digit.
 Sorry for my English (I studied German).

#!/usr/bin/perl -w
use strict;

my $s='012-34-56789 123-45-6789 012-34-5678';
my $result;
our $temp;
print "$result\n" if $s =~ /(?{local $temp=''})(?<!\d)(\d(?{$temp.=chr vec($s,pos($s)-1,8)})-?){9}(?![\d-])(?{$result=$temp})/;

# Output: 123456789


Regards,
Serge
http://www.gameintellect.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
Do I need regular expressions..? ypomonh XSLT 2 May 20th, 2007 05:09 PM
Regular expressions on C# hideway C# 2 November 27th, 2006 05:08 PM
Basic Regular Expressions help needed Lwlgeorge BOOK: Beginning Regular Expressions 9 May 31st, 2006 07:03 AM
regular expressions help kyootepuffy Classic ASP Databases 2 September 10th, 2003 01:37 PM
Regular Expressions Dave Doknjas C# 1 August 9th, 2003 12:05 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.