Fixed horrible Bash regex performance matching with two placeholders. Instead use fast one and extract remaining part.
authorOleksandr Gavenko <gavenkoa@gmail.com>
Wed, 16 Jun 2021 15:24:53 +0300
changeset 990 582cddcfb6a6
parent 989 5b3759d3d789
child 991 57fda390e91c
Fixed horrible Bash regex performance matching with two placeholders. Instead use fast one and extract remaining part.
.env.bash
--- a/.env.bash	Wed Jun 16 14:48:32 2021 +0300
+++ b/.env.bash	Wed Jun 16 15:24:53 2021 +0300
@@ -23,9 +23,9 @@
 export CDPATH=.:$HOME:$HOME/devel:$HOME/my
 
 my_path_prune() {
-  if [[ :$1: =~ (.*):$2:(.*) ]]; then
+  if [[ :$1: =~ (.*):$2: ]]; then
     local left=${BASH_REMATCH[1]}
-    local right=${BASH_REMATCH[2]}
+    local right=${1:$((${#left} + ${#2} + 1))}
     [[ ${left:0:1} = : ]] && left=${left:1}
     [[ ${right: -1} = : ]] && right=${right:0: -1}
     if [[ -z $left ]]; then