[prev in list] [next in list] [prev in thread] [next in thread]
List: bash-bug
Subject: Re: + vs. [^/]* - Regular Expression bug?
From: Greg Wooledge <wooledg () eeg ! ccf ! org>
Date: 2010-02-11 13:40:17
Message-ID: 20100211134017.GP1486 () eeg ! ccf ! org
[Download RAW message or body]
On Tue, Feb 09, 2010 at 09:18:47PM -0800, DennisW wrote:
> * means zero or more characters. It found zero and stopped. You could
> do:
>
> [[ '/home/' =~ /([^/]*) ]]; echo ${BASH_REMATCH[1]}
Oh, is he trying to get the first non-null component of a /-delimited
pathname? I can never tell any more....
IFS=/ read -a tmp <<< '/home/'; echo "${tmp[1]}"
Using regular expressions to split a string into fields is so unnatural
to me. ${tmp[1]} is the second element of the array. If you need to
search through it for the first non-null element, you can write a loop
for that.
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic