[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Cross-version regular expression...
From: |
Ray Van Dolson |
Subject: |
Re: Cross-version regular expression... |
Date: |
Wed, 13 Apr 2011 13:15:51 -0700 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
On Wed, Apr 13, 2011 at 12:28:39PM -0700, Greg Wooledge wrote:
> On Wed, Apr 13, 2011 at 11:19:22AM -0700, Ray Van Dolson wrote:
> > I'm trying to get regular expression matching working on both bash v3
> > as well as v4.
>
> Put the RE in a variable.
>
> > The following works on v4 (under RHEL6), but not under bash 3.00.15
> > (under RHEL4):
> >
> > [[ "6Server" =~ ([0-9]+)(.*) ]]
>
> Put the RE in a variable.
>
> > This works on 3.00.15, but not under RHEL6's bash (4.1.2):
> >
> > [[ "6Server" =~ '([0-9]+)(.*)' ]]
>
> Put the RE in a variable. Don't quote the right hand side. If you quote
> the right hand side, it becomes == matching instead of =~ matching.
>
> re='([0-9]+)(.*)'
> [[ 6Server =~ $re ]]
>
Thanks Greg!