On Sat, Jul 25, 2009 at 05:48, Shawn H. Corey<shawnhco...@gmail.com> wrote: > Umar Draz wrote: >> >> As you can see its not works because there is no space after the word is >> So would you please help me how to solve this. >> > > Change the word boundary, \b, to a not-digit, \D. snip
That will cause "0300-1234567" to fail (\b is zero-width, but \D is not). You need a [zero-width negative look behind][1] and a [zero-width negative look ahead][2]. You also need to simplify that regex. How did you build it? And one last bit of warning: you have used \d when it looks like what you want to match is [0-9]. As of Perl 5.8, \d matches any UNICODE digit character, not just [0-9]. You probably should change the 03 part of the regex to match any 0 and 3 UNICODE digits (and that is a big character class), or switch to using [0-9] instead of \d. #!/usr/bin/perl use strict; use warnings; my $s = join '', <DATA>; my @mobile_numbers = $s =~ /(?<!\d) ( 03 (?: \d\d-\d{7} | \d{9} ) ) (?!\d)/gx; print "found the numbers:\n", map { "\t$_\n" } @mobile_numbers; my $unicode = "0300-\x{0e53}\x{0e53}\x{0e53}\x{0e53}\x{0e53}\x{0e53}\x{0e53}"; print "$unicode ", $unicode =~ /(?<!\d)(03(?:\d\d-\d{7}|\d{9})(?!\d))/g ? "matches" : "does not match", "\n"; __DATA__ These should not match 10300-1234567 203123456789. Nor should these 0300-12345671 031234567892. Total Mobile HONDA Civic, EXI: model 2002, excellent condition, available for sale. My Phone # is. 042-6832797, My Cell. 0300-4459899, My Office Cell is0300-5009228, my other mobile no is 0356-4094030, my Friend Mobile no is03226789871. [1] : http://perldoc.perl.org/perlre.html#%28?%3C!pattern%29 [2] : http://perldoc.perl.org/perlre.html#%28?!pattern%29 -- Chas. Owens wonkden.net The most important skill a programmer can have is the ability to read. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/