[Top][All Lists]

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

Re: [DOC] Incomplete explanation about the regex =~ operator

From: Greg Wooledge
Subject: Re: [DOC] Incomplete explanation about the regex =~ operator
Date: Tue, 8 Jan 2019 08:44:06 -0500
User-agent: NeoMutt/20170113 (1.7.2)

On Tue, Jan 08, 2019 at 10:47:21AM +0000, gilaro wrote:
> See also: Does bash support word boundary regular expressions?

Short answer: No.

Long answer: Bash's =~ operator uses Extended Regular Expressions (ERE), as
implemented by your system's C library's regular expression engine.  Your
system may or may not offer extensions beyond the standard POSIX definition
of ERE.  Any such extensions would by definition render your script
non-portable, if you write code which relies on them.

> I am trying to match on the presence of a word in a list before adding that 
> word again (to avoid duplicates). I ...

Use an associative array instead of an indexed array.  Associative
arrays give you a natural, efficient way to determine whether an element
is present in a set.

If you also need to preserve the order of your list, then you may use
both an indexed array (to preserve the order) AND an associative array
(to check for existence efficiently).

reply via email to

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