Extended Regular Expression in UNIX
NickName:Mahmoud Emam Ask DateTime:2013-04-14T22:23:12

Extended Regular Expression in UNIX

I don't mean that this question for UNIX only, but I work on Solaris, and I didn't try it on any other OS. I confused between the extended regular expression:

first:

[[ "str" == ?(str|STR) ]] && echo "matched"

this work correct, but when:

[[ "str str" == ?(str|STR)(.*) ]] && echo "matched"

it doesn't work, does it mean that I can only compare one pattern.

Second:

[[ "str" =~ ?(str|STR) ]] && echo "matched"

I can't use this form here why?, but when:

[[ "str" == (str|STR)? ]] && echo "matched"

it works correctly.

Copyright Notice:Content Author:「Mahmoud Emam」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/16000097/extended-regular-expression-in-unix

More about “Extended Regular Expression in UNIX” related questions

Extended Regular Expression in UNIX

I don't mean that this question for UNIX only, but I work on Solaris, and I didn't try it on any other OS. I confused between the extended regular expression: first: [[ "str" == ?(str|STR) ]] &am...

Show Detail

Date Regular Expression in UNIX

I'm trying to write a regular expression to validate a date in Unix. The regex that matches a date in the usual format is mm/dd/yy For example, it should match 03/20/98 or 11/08/89 but not 13/40...

Show Detail

Unix regular expression

I need to use unix regular expression in unix find command: find "/home/user/somePath/" -maxdepth 1 ! -regex "/home/user/somePath/someUnwantedPath" ! -regex "/home/user/somePath/

Show Detail

Unix regular expression begginers question

I'm starting the study of regular expressions and I've been wondering how can I build and test the regular expression in UNIX notation for all vowel strings that contain the substring "ai&quot...

Show Detail

Regular expression to extract everything between braces in unix

I am trying to extract everything between braces from a text file and write the output to another text file. I was able to construct a regular expression to match everything between {} and it works...

Show Detail

What is the most correct regular expression for a UNIX file path?

What is the most correct regular expression (regex) for a UNIX file path? For example, to detect something like this: /usr/lib/libgccpp.so.1.0.2 It's pretty easy to make a regular expression tha...

Show Detail

Basic UNIX regular expression in python

I'm trying to use the re.match() method to check if my string looks like the regular expression. In UNIX on the cmd line I'd use "*,*" to check against a string such as, hello,there. The follow...

Show Detail

Find and Replace multiple strings using a POSIX extended regular expression

I am using Snowflake database and hope to find a single expression that will find and replace multiple items. The column in question has rows containing, Y, Yes, N, NO, and other irrelevant string...

Show Detail

Extended regular expression grouping

Trying to understand grouping in extended regular expressions. What is the difference between following two extended regular expressions. $ echo "the CPU is" | grep -E '[Tt]he CPU|compute...

Show Detail

How to write a C program for Unix that can process the Regular Expression ?

I want creat a C program for Unix that can porcess the Regular Expression,like a simple Perl interpreter. Do I have to personally write an regexp engine?

Show Detail