LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-02-2006, 10:07 AM   #1
introuble
Member
 
Registered: Apr 2004
Distribution: Debian -unstable
Posts: 700

Rep: Reputation: 31
Perl: Check if "$str" is of type [A-Z]<char string>[0-9][0-9]


Hello !

In a Perl script, I have a string, $str. I need to check if the string is of the form: [A-Z]<string consisting of chars a-z>[0-9][0-9] and print "yes" if it is, "no" if it isn't.

Matching examples: Awhatever49, Xwhenever30, Paaaa00, Thisisnice73.

Can anyone help me with this ?
 
Old 06-02-2006, 10:24 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

Something like this should work:
Code:
#!/usr/bin/perl

#$str = "Awhatever49";
$str = "W49";

if ( $str =~ /[A-Z][a-z][a-z]*[0-9][0-9]/) {
  print "Yes.\n"
} else {
  print "No.\n"
}
Hope this helps.
 
Old 06-02-2006, 10:33 AM   #3
introuble
Member
 
Registered: Apr 2004
Distribution: Debian -unstable
Posts: 700

Original Poster
Rep: Reputation: 31
Danke schon
 
  


Reply

Tags
perl



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to convert "string" type to "char * " in c++ pranavojha Programming 18 06-05-2008 03:10 PM
bash cripting function to "identify" any char in a string? minike Programming 8 02-01-2006 09:45 AM
using java to find the location of the "\" char in a string caged Programming 8 02-03-2004 10:42 AM
<input type="button" disabled="true" > does not work in ns4.7 or 4.9 cybercop12us Programming 2 11-29-2002 08:31 AM
Cannot convert string "%s" to type %s jamaso Slackware 1 05-05-2002 04:06 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:40 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration