RegEx with d doesn’t work in if-else statement with [[
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
i wrote the following script. It will be used in a build process later. My goal is to decide whether it's a pre release or a release. To archive this i compare $release to a RegEx.
If my RegEx matches it's a pre release, if not it's a release.
#/bin/bash
release="1.9.2-alpha1"
echo "$release"
if [[ "$release" =~ d+.d+.d+[-]+.* ]];then
echo "Pre"
else
echo "Release"
fi
But as result i always end up with the following:
~$ bash releasescript.sh
1.9.2-alpha1
Release
Version:
Ubuntu 18.04.1 LTS
I used this editor to test my RegEx. I'm stuck for at least 6h, so i would appreciate some help greatly.
command-line bash scripts regex
add a comment |
i wrote the following script. It will be used in a build process later. My goal is to decide whether it's a pre release or a release. To archive this i compare $release to a RegEx.
If my RegEx matches it's a pre release, if not it's a release.
#/bin/bash
release="1.9.2-alpha1"
echo "$release"
if [[ "$release" =~ d+.d+.d+[-]+.* ]];then
echo "Pre"
else
echo "Release"
fi
But as result i always end up with the following:
~$ bash releasescript.sh
1.9.2-alpha1
Release
Version:
Ubuntu 18.04.1 LTS
I used this editor to test my RegEx. I'm stuck for at least 6h, so i would appreciate some help greatly.
command-line bash scripts regex
add a comment |
i wrote the following script. It will be used in a build process later. My goal is to decide whether it's a pre release or a release. To archive this i compare $release to a RegEx.
If my RegEx matches it's a pre release, if not it's a release.
#/bin/bash
release="1.9.2-alpha1"
echo "$release"
if [[ "$release" =~ d+.d+.d+[-]+.* ]];then
echo "Pre"
else
echo "Release"
fi
But as result i always end up with the following:
~$ bash releasescript.sh
1.9.2-alpha1
Release
Version:
Ubuntu 18.04.1 LTS
I used this editor to test my RegEx. I'm stuck for at least 6h, so i would appreciate some help greatly.
command-line bash scripts regex
i wrote the following script. It will be used in a build process later. My goal is to decide whether it's a pre release or a release. To archive this i compare $release to a RegEx.
If my RegEx matches it's a pre release, if not it's a release.
#/bin/bash
release="1.9.2-alpha1"
echo "$release"
if [[ "$release" =~ d+.d+.d+[-]+.* ]];then
echo "Pre"
else
echo "Release"
fi
But as result i always end up with the following:
~$ bash releasescript.sh
1.9.2-alpha1
Release
Version:
Ubuntu 18.04.1 LTS
I used this editor to test my RegEx. I'm stuck for at least 6h, so i would appreciate some help greatly.
command-line bash scripts regex
command-line bash scripts regex
edited May 16 at 11:08
venter
asked May 16 at 10:13
venterventer
1384
1384
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
d and w don't work in POSIX regular expressions, you could use [[:digit:]] though
#/bin/bash
release="1.9.2-alpha1"
echo "$release"
LANG=C # This needed only if script will be used in locales where digits not 0-9
if [[ "$release" =~ ^[[:digit:]]+.[[:digit:]]+.[[:digit:]]+-+ ]];then
echo "Pre"
else
echo "Release"
fi
I have tested this script, it output "Pre" for given $release
Checked out your regex builder, it works only with perl compatible and javascript regex, while you need posix, or posix extended.
By @dessert:
[0-9]is the shorter alternative to[[:digit:]]. As the beginning
of the string is to be matched, one should add^, while.*at the
end is superfluous:^[0-9]+.[0-9]+.[0-9]+-+– using a group this
can be further shortened to:^([0-9]+.){2}[0-9]+-+
4
Beat me to it! Also, fwiw if you'd usedshellcheckthen it has a warning "SC1001: This d will be a regular 'd' in this context.", which is quite helpful. Other answers.
– pbhj
May 16 at 10:45
2
Is [0-9] equivalent to [[:digit:]] though? I was under the impression that POSIX character classes match Unicode characters, so could very well match digits in languages that don't use 0-9.
– Fax
May 16 at 12:38
@Fax Not sure about [0-9] but [A-Z] match unicode characters, the way to change that is only set locale byLANG=C
– LeonidMew
May 16 at 12:46
1
@Fax "Is [0-9] equivalent to [[:digit:]] though?" TIL that the answer is no.
– levant pied
May 16 at 20:25
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1143710%2fregex-with-d-doesn-t-work-in-if-else-statement-with%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
d and w don't work in POSIX regular expressions, you could use [[:digit:]] though
#/bin/bash
release="1.9.2-alpha1"
echo "$release"
LANG=C # This needed only if script will be used in locales where digits not 0-9
if [[ "$release" =~ ^[[:digit:]]+.[[:digit:]]+.[[:digit:]]+-+ ]];then
echo "Pre"
else
echo "Release"
fi
I have tested this script, it output "Pre" for given $release
Checked out your regex builder, it works only with perl compatible and javascript regex, while you need posix, or posix extended.
By @dessert:
[0-9]is the shorter alternative to[[:digit:]]. As the beginning
of the string is to be matched, one should add^, while.*at the
end is superfluous:^[0-9]+.[0-9]+.[0-9]+-+– using a group this
can be further shortened to:^([0-9]+.){2}[0-9]+-+
4
Beat me to it! Also, fwiw if you'd usedshellcheckthen it has a warning "SC1001: This d will be a regular 'd' in this context.", which is quite helpful. Other answers.
– pbhj
May 16 at 10:45
2
Is [0-9] equivalent to [[:digit:]] though? I was under the impression that POSIX character classes match Unicode characters, so could very well match digits in languages that don't use 0-9.
– Fax
May 16 at 12:38
@Fax Not sure about [0-9] but [A-Z] match unicode characters, the way to change that is only set locale byLANG=C
– LeonidMew
May 16 at 12:46
1
@Fax "Is [0-9] equivalent to [[:digit:]] though?" TIL that the answer is no.
– levant pied
May 16 at 20:25
add a comment |
d and w don't work in POSIX regular expressions, you could use [[:digit:]] though
#/bin/bash
release="1.9.2-alpha1"
echo "$release"
LANG=C # This needed only if script will be used in locales where digits not 0-9
if [[ "$release" =~ ^[[:digit:]]+.[[:digit:]]+.[[:digit:]]+-+ ]];then
echo "Pre"
else
echo "Release"
fi
I have tested this script, it output "Pre" for given $release
Checked out your regex builder, it works only with perl compatible and javascript regex, while you need posix, or posix extended.
By @dessert:
[0-9]is the shorter alternative to[[:digit:]]. As the beginning
of the string is to be matched, one should add^, while.*at the
end is superfluous:^[0-9]+.[0-9]+.[0-9]+-+– using a group this
can be further shortened to:^([0-9]+.){2}[0-9]+-+
4
Beat me to it! Also, fwiw if you'd usedshellcheckthen it has a warning "SC1001: This d will be a regular 'd' in this context.", which is quite helpful. Other answers.
– pbhj
May 16 at 10:45
2
Is [0-9] equivalent to [[:digit:]] though? I was under the impression that POSIX character classes match Unicode characters, so could very well match digits in languages that don't use 0-9.
– Fax
May 16 at 12:38
@Fax Not sure about [0-9] but [A-Z] match unicode characters, the way to change that is only set locale byLANG=C
– LeonidMew
May 16 at 12:46
1
@Fax "Is [0-9] equivalent to [[:digit:]] though?" TIL that the answer is no.
– levant pied
May 16 at 20:25
add a comment |
d and w don't work in POSIX regular expressions, you could use [[:digit:]] though
#/bin/bash
release="1.9.2-alpha1"
echo "$release"
LANG=C # This needed only if script will be used in locales where digits not 0-9
if [[ "$release" =~ ^[[:digit:]]+.[[:digit:]]+.[[:digit:]]+-+ ]];then
echo "Pre"
else
echo "Release"
fi
I have tested this script, it output "Pre" for given $release
Checked out your regex builder, it works only with perl compatible and javascript regex, while you need posix, or posix extended.
By @dessert:
[0-9]is the shorter alternative to[[:digit:]]. As the beginning
of the string is to be matched, one should add^, while.*at the
end is superfluous:^[0-9]+.[0-9]+.[0-9]+-+– using a group this
can be further shortened to:^([0-9]+.){2}[0-9]+-+
d and w don't work in POSIX regular expressions, you could use [[:digit:]] though
#/bin/bash
release="1.9.2-alpha1"
echo "$release"
LANG=C # This needed only if script will be used in locales where digits not 0-9
if [[ "$release" =~ ^[[:digit:]]+.[[:digit:]]+.[[:digit:]]+-+ ]];then
echo "Pre"
else
echo "Release"
fi
I have tested this script, it output "Pre" for given $release
Checked out your regex builder, it works only with perl compatible and javascript regex, while you need posix, or posix extended.
By @dessert:
[0-9]is the shorter alternative to[[:digit:]]. As the beginning
of the string is to be matched, one should add^, while.*at the
end is superfluous:^[0-9]+.[0-9]+.[0-9]+-+– using a group this
can be further shortened to:^([0-9]+.){2}[0-9]+-+
edited May 16 at 13:09
answered May 16 at 10:41
LeonidMewLeonidMew
1,8851127
1,8851127
4
Beat me to it! Also, fwiw if you'd usedshellcheckthen it has a warning "SC1001: This d will be a regular 'd' in this context.", which is quite helpful. Other answers.
– pbhj
May 16 at 10:45
2
Is [0-9] equivalent to [[:digit:]] though? I was under the impression that POSIX character classes match Unicode characters, so could very well match digits in languages that don't use 0-9.
– Fax
May 16 at 12:38
@Fax Not sure about [0-9] but [A-Z] match unicode characters, the way to change that is only set locale byLANG=C
– LeonidMew
May 16 at 12:46
1
@Fax "Is [0-9] equivalent to [[:digit:]] though?" TIL that the answer is no.
– levant pied
May 16 at 20:25
add a comment |
4
Beat me to it! Also, fwiw if you'd usedshellcheckthen it has a warning "SC1001: This d will be a regular 'd' in this context.", which is quite helpful. Other answers.
– pbhj
May 16 at 10:45
2
Is [0-9] equivalent to [[:digit:]] though? I was under the impression that POSIX character classes match Unicode characters, so could very well match digits in languages that don't use 0-9.
– Fax
May 16 at 12:38
@Fax Not sure about [0-9] but [A-Z] match unicode characters, the way to change that is only set locale byLANG=C
– LeonidMew
May 16 at 12:46
1
@Fax "Is [0-9] equivalent to [[:digit:]] though?" TIL that the answer is no.
– levant pied
May 16 at 20:25
4
4
Beat me to it! Also, fwiw if you'd used
shellcheck then it has a warning "SC1001: This d will be a regular 'd' in this context.", which is quite helpful. Other answers.– pbhj
May 16 at 10:45
Beat me to it! Also, fwiw if you'd used
shellcheck then it has a warning "SC1001: This d will be a regular 'd' in this context.", which is quite helpful. Other answers.– pbhj
May 16 at 10:45
2
2
Is [0-9] equivalent to [[:digit:]] though? I was under the impression that POSIX character classes match Unicode characters, so could very well match digits in languages that don't use 0-9.
– Fax
May 16 at 12:38
Is [0-9] equivalent to [[:digit:]] though? I was under the impression that POSIX character classes match Unicode characters, so could very well match digits in languages that don't use 0-9.
– Fax
May 16 at 12:38
@Fax Not sure about [0-9] but [A-Z] match unicode characters, the way to change that is only set locale by
LANG=C– LeonidMew
May 16 at 12:46
@Fax Not sure about [0-9] but [A-Z] match unicode characters, the way to change that is only set locale by
LANG=C– LeonidMew
May 16 at 12:46
1
1
@Fax "Is [0-9] equivalent to [[:digit:]] though?" TIL that the answer is no.
– levant pied
May 16 at 20:25
@Fax "Is [0-9] equivalent to [[:digit:]] though?" TIL that the answer is no.
– levant pied
May 16 at 20:25
add a comment |
Thanks for contributing an answer to Ask Ubuntu!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1143710%2fregex-with-d-doesn-t-work-in-if-else-statement-with%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown