LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 12-21-2009, 12:56 PM   #1
matt007
LQ Newbie
 
Registered: Jun 2008
Posts: 14

Rep: Reputation: 0
reg expr: match a string A-Z, a-z, * or a blank ( but string can not be all blanks)


I need to match a string that can contain an A-Z, a-z, * or a blank
( but the string can not be all blanks)...

Is my attempt correct?


if (string not like "%[^A-Za-z* ]%")
begin
//do something
end
 
Old 12-21-2009, 01:12 PM   #2
tuxdev
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 2,012

Rep: Reputation: 115Reputation: 115
Code:
#!/usr/bin/env bash

RE=' *[[:alpha:]*][[:alpha:]* ]*'
if ! [[ "$1" =~ $RE ]] ; then
   echo "Invalid!"
fi
 
Old 12-21-2009, 01:48 PM   #3
matt007
LQ Newbie
 
Registered: Jun 2008
Posts: 14

Original Poster
Rep: Reputation: 0
is there anything on the lines of

if (string not like "%[^A-Za-z* ]%")
begin
//do something
end
 
Old 12-21-2009, 06:33 PM   #4
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
show some examples of those strings, the correct matches , and the incorrect matches.
 
Old 12-22-2009, 08:55 AM   #5
matt007
LQ Newbie
 
Registered: Jun 2008
Posts: 14

Original Poster
Rep: Reputation: 0
FOLLOWING SHOULD PASS:

"this is my string"
"**"

FOLLOWING SHOULD FAIL:

"this is 908 string"
" " ( an all blank string)

IN GENERAL:

A valid string will contain values A-Z, a-z, one or more blanks or an asterisk ( "*").

But string can not be all blank.
 
  


Reply



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
perl string match issue knockout_artist Linux - Newbie 11 01-13-2009 05:53 PM
How to find a match string in conf file Ameii83 Linux - Newbie 6 08-12-2008 07:42 PM
iptables string match htb Linux - Networking 2 08-30-2006 02:37 PM
iptables string match kahpeetan Linux - Security 3 11-09-2003 06:36 PM
how to grep only one string pr match gummimann Linux - General 3 11-06-2003 09:40 AM

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

All times are GMT -5. The time now is 10:06 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