LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   reg expr: match a string A-Z, a-z, * or a blank ( but string can not be all blanks) (https://www.linuxquestions.org/questions/programming-9/reg-expr-match-a-string-a-z-a-z-%2A-or-a-blank-but-string-can-not-be-all-blanks-777277/)

matt007 12-21-2009 12:56 PM

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

tuxdev 12-21-2009 01:12 PM

Code:

#!/usr/bin/env bash

RE=' *[[:alpha:]*][[:alpha:]* ]*'
if ! [[ "$1" =~ $RE ]] ; then
  echo "Invalid!"
fi


matt007 12-21-2009 01:48 PM

is there anything on the lines of

if (string not like "%[^A-Za-z* ]%")
begin
//do something
end

ghostdog74 12-21-2009 06:33 PM

show some examples of those strings, the correct matches , and the incorrect matches.

matt007 12-22-2009 08:55 AM

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.


All times are GMT -5. The time now is 02:02 PM.