-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature] Ability to use extended regex syntax in sed #444
Comments
We have the support for default value for function parameters in the alpha in development. |
I realise there may be I would respectfully suggest that if anyone does have a non standard |
Great! Can you point me at an example please? |
So this is not a breaking change after all:
|
iirc, sed's syntax differs a bit with gnu and bsd versions. im pretty sure alpine has its own stripped down sed too. the bsd version is used on all macOS systems, and gnu is on most linux ones |
yup, i was right about alpine:
|
i think we could check version=$(sed --version 2>&1)
if echo $version | grep 'Copyright (C) ' | grep ' Free Software Foundation, Inc.' 2>&1 > /dev/null; then
echo is gnu
fi
if echo $version | grep 'This is not GNU sed version ' 2>&1 > /dev/null; then
echo is alpine (busybox)
fi
if echo $version | grep 'sed: illegal option -- -' 2>&1 > /dev/null; then
echo is bsd
fi |
My proposal is to default to So I think all we really need to test for is "GNU or not GNU"; we might as well simplify the generated Bash output, especially as Mte90 requested that we test the flavour each time I am happy to search for |
I do also wonder how standardised the actual extended regex syntax is across flavours, but quite honestly it's going to be a losing game trying to correct for any disparities, and I think we can reasonably leave that to Amber script authors (it might be handy to provide a way of testing the OS type, but that's a topic for another day). |
Tested on MacOS:
|
they do not support the same regexes, and their engines differ a little bit |
I suspected as much, but I really don't think there's a lot we can do about masking those differences. After all, script authors would have to tailor the regex syntax if they were calling |
I note that standard library function
replace_regex()
transpiles to the followingsed
command:sed
basic regex syntax is horrible, as you have to unexpectedly (IMHO) escape regex tokens like capturing parentheses(...)
, and it doesn't support the "one or more instances" token+
. I therefore usesed -E
, and it would be nice to have that option.I believe the aim of Amber is to be as widely applicable as possible, and I understand that some Bash distributions do not support
sed -E
or the equivalentsed -r
, so we can't necessarily just change it in the standard library. I would therefore like to propose a breaking change:It may even be possible to provide default parameters to Amber functions, but I do not believe this is currently implemented.
Thoughts?
The text was updated successfully, but these errors were encountered: