bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to match regex in bash? (any character)


From: Roger
Subject: Re: How to match regex in bash? (any character)
Date: Mon, 26 Sep 2011 19:48:25 -0800
User-agent: Mutt/1.5.21 (2010-09-15)

> On Mon, Sep 26, 2011 at 09:37:07PM -0500, Dennis Williamson wrote:
>On Mon, Sep 26, 2011 at 8:19 PM, Peng Yu <pengyu.ut@gmail.com> wrote:
>> Hi,
>>
>> I know that I should use =~ to match regex (bash version 4).
>>
>> However, the man page is not very clear. I don't find how to match
>> (matching any single character). For example, the following regex
>> doesn't match xxxxtxt. Does anybody know how to match any character
>> (should be '.' in perl) in bash.
>>
>> [[ "$1" =~ "xxx.txt" ]]
>>
>
>When you quote the string on the right hand side of =~ it changes to a
>simple string match instead of a regex match. It is sometimes
>difficult to specify a regex literally (and unquoted), so it's best to
>use a variable as shown in Steven's reply to you.
>

I believe the Bash Manual also strongly suggests, using variables for matching
as well. ;-)

-- 
Roger
http://rogerx.freeshell.org/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]