Perl

Moderators: Jonathan
Number of threads: 1236
Number of posts: 3605

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
regular expressions Posted by tonyn on 17 Jan 2008 at 10:12 PM
Hi,

How to check one or more letter strings follow by two or more digit numbers.
If I have $line contains data:

new YOR CiTy 55
boston 66


I have the code below but it only checks from 1 to 3 letter strings but I want to check more than 3 letter strings. How can I do it?

$line !~ /^\s*([a-zA-Z]+)\s*([a-zA-Z]+)\s*([a-zA-Z]+)\s*\d{2,}$/)

Many thanks,
Tony
Report
Re: regular expressions Posted by dbrandt on 17 Jan 2008 at 10:21 PM
I'm not sure what you're doing with your regex. If I'm not mistaken it can be much more simple:
/^([a-z]\i)+.*(([0-9]){2})$/


The "\i" means "case-insensitive"
Report
Re: regular expressions Posted by tonyn on 18 Jan 2008 at 11:05 AM
: I'm not sure what you're doing with your regex. If I'm not mistaken
: it can be much more simple:
:
: 
: /^([a-z]\i)+.*(([0-9]){2})$/
: 
:
:
: The "\i" means "case-insensitive"
:


It is working. Many thanks

Tony



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.