Replies: 4 comments
-
I can't reproduce this on Fedora 41 $ [[ 666F6FC7ADE88F =~ ^(0{2})([[:xdigit:]]{2}) ]] ; echo $?
1
$ echo $BASH_VERSION
5.2.26(1)-release The curly brace notation here is a bound, as described in regex(7), which bash should conform to by default, if I'm not mistaken. I don't why it would be different on cygwin. |
Beta Was this translation helpful? Give feedback.
-
Sorry, I left out the '*'s in my example. [[ 666F6FC7ADE88F =~ ^(0{2}*)([[:xdigit:]]{2}*) ]] After rolling up my sleeves, I found Cygwin not only reports syntax but also provides a different answer. cygwin (5.2.21(1)-release): $ [[ 666F6FC7ADE88F =~ ^(0{2}*)([[:xdigit:]]{2}*) ]]
$ echo $\?=$? 0=${BASH_REMATCH[0]} 1=${BASH_REMATCH[1]} 2=${BASH_REMATCH[2]} 3=${BASH_REMATCH[3]} 4=${BASH_REMATCH[4]}
$?=2 0=666F6FC7ADE88F 1= 2= 3=666F6FC7ADE88F 4=8F Instead of the expected (Linux 4.4.302+ / bash 4.4.23(1)-release): $?=0 0=666F6FC7ADE88F 1= 2=666F6FC7ADE88F 3= 4= The issue is forming a "piece" by following an "atom" with both a bound and '*'. A fix would be to add '(' and ')' around the piece to form another atom like: $ [[ 666F6FC7ADE88F =~ ^((0{2})*)(([[:xdigit:]]{2})*) ]] this gives consistent output on cygwin and linux (at least mine). $?=0 0=666F6FC7ADE88F 1= 2= 3=666F6FC7ADE88F 4=8F Of course, you would have to adjust your use of BASH_REMATCH[n] to ensure that you reference the n you want. David |
Beta Was this translation helpful? Give feedback.
-
You are correct that a piece is not supposed to be followed by either '*', '+' etc. So it may actually be cygwin which is right here. I'm not too keen on adding parenthesis as they add captures but this may be the only correct way to do it unfortunately. Non capturing groups
|
Beta Was this translation helpful? Give feedback.
-
I'm happy to see you crossed out the grep instead! :) shopt -s extglob
In=000123
Right=${In#+(00)}; Left=${In%$Right}
echo Left=$Left Right=$Right Left is any 00 (zero pairs), and Right is the rest. ${Right//[^0-9a-fA-f]} Or if you want to check and not correct, you can compare the fixed version [ "$In" = "$Left$Right" ] ... |
Beta Was this translation helpful? Give feedback.
-
bash reports a syntax issue :
$ [[ 666F6FC7ADE88F =~ ^(0{2})([[:xdigit:]]{2}) ]]
$ echo $?
2
Removing the {2}s is a workaround:
[[ $REPLY =~ ^(0*)([[:xdigit:]]*) ]]
bitcoin-bash-tools/bitcoin.sh
Line 151 in 8661db2
Beta Was this translation helpful? Give feedback.
All reactions