[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to match regex in bash? (any character)
From: |
Dennis Williamson |
Subject: |
Re: How to match regex in bash? (any character) |
Date: |
Mon, 26 Sep 2011 21:37:07 -0500 |
On Mon, Sep 26, 2011 at 8:19 PM, Peng Yu <address@hidden> 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" ]]
>
>
> --
> Regards,
> Peng
>
>
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.
The quoting is most likely unnecessary on the left hand side as well.
--
Visit serverfault.com to get your system administration questions answered.
- How to match regex in bash? (any character), Peng Yu, 2011/09/26
- Re: How to match regex in bash? (any character), Steven W. Orr, 2011/09/26
- Re: How to match regex in bash? (any character),
Dennis Williamson <=
- Re: How to match regex in bash? (any character), John Reiser, 2011/09/26
- Re: How to match regex in bash? (any character), Roger, 2011/09/26
- Re: How to match regex in bash? (any character), Greg Wooledge, 2011/09/27
- Re: How to match regex in bash? (any character), Roger, 2011/09/27
- Re: How to match regex in bash? (any character), Chet Ramey, 2011/09/27
- Re: How to match regex in bash? (any character), Peng Yu, 2011/09/27
- Re: How to match regex in bash? (any character), Roger, 2011/09/28
- Re: How to match regex in bash? (any character), Chet Ramey, 2011/09/29