From b313f62749a68ed138952dcee8888a68829c3cd7 Mon Sep 17 00:00:00 2001
From: Koen Punt <koen@koenpunt.nl>
Date: Wed, 7 May 2014 01:15:52 +0200
Subject: [PATCH 1/2] Use sed -e instead of -E

---
 nvm.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/nvm.sh b/nvm.sh
index 696cf35..22d826a 100644
--- a/nvm.sh
+++ b/nvm.sh
@@ -98,7 +98,7 @@ nvm_format_version() {
 }
 
 nvm_strip_path() {
-  echo "$1" | sed -E "s#$NVM_DIR/[^/]*$2[^:]*:?##g"
+  echo "$1" | sed -e "s#$NVM_DIR/[^/]*$2[^:]*##g" | sed -e "s/::/:/g" | sed -e "s/:$//g"
 }
 
 nvm_binary_available() {

From e3b84499c26564635d928e83668464e2515e3d30 Mon Sep 17 00:00:00 2001
From: Koen Punt <koen@koenpunt.nl>
Date: Wed, 7 May 2014 10:47:24 +0200
Subject: [PATCH 2/2] use regex triplet, add unit test

---
 nvm.sh                              |  2 +-
 test/fast/Unit tests/nvm_strip_path | 11 +++++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)
 create mode 100755 test/fast/Unit tests/nvm_strip_path

diff --git a/nvm.sh b/nvm.sh
index 22d826a..5724da7 100644
--- a/nvm.sh
+++ b/nvm.sh
@@ -98,7 +98,7 @@ nvm_format_version() {
 }
 
 nvm_strip_path() {
-  echo "$1" | sed -e "s#$NVM_DIR/[^/]*$2[^:]*##g" | sed -e "s/::/:/g" | sed -e "s/:$//g"
+  echo "$1" | sed -e "s#$NVM_DIR/[^/]*$2[^:]*:##g" -e "s#:$NVM_DIR/[^/]*$2[^:]*##g" -e "s#$NVM_DIR/[^/]*$2[^:]*##g"
 }
 
 nvm_binary_available() {
diff --git a/test/fast/Unit tests/nvm_strip_path b/test/fast/Unit tests/nvm_strip_path
new file mode 100755
index 0000000..0d119aa
--- /dev/null
+++ b/test/fast/Unit tests/nvm_strip_path	
@@ -0,0 +1,11 @@
+#!/bin/sh
+
+die () { echo $@ ; exit 1; }
+
+. ../../../nvm.sh
+
+TEST_PATH=$NVM_DIR/v0.10.5/bin:/usr/bin:$NVM_DIR/v0.11.5/bin:$NVM_DIR/v0.9.5/bin:/usr/local/bin:$NVM_DIR/v0.2.5/bin
+
+STRIPPED_PATH=`nvm_strip_path "$TEST_PATH" "/bin"`
+
+[ "$STRIPPED_PATH" = "/usr/bin:/usr/local/bin" ] || die "Not correctly stripped: $STRIPPED_PATH "