[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: + vs. [^/]* - Regular Expression bug?
From: |
Greg Wooledge |
Subject: |
Re: + vs. [^/]* - Regular Expression bug? |
Date: |
Thu, 11 Feb 2010 08:40:17 -0500 |
User-agent: |
Mutt/1.4.2.3i |
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.