Does a dot have to be escaped in a character class (square brackets) of a regular expression?
A dot .
in a regular expression matches any single character. In order for regex to match a dot, the dot has to be escaped: .
It has been pointed out to me that inside square brackets a dot does not have to be escaped. For example, the expression:
[.]{3}
would match ...
string.
Doesn't it, really? And if so, is it true for all regex standards?
regex standards standards-compliance square-bracket
|
show 1 more comment
A dot .
in a regular expression matches any single character. In order for regex to match a dot, the dot has to be escaped: .
It has been pointed out to me that inside square brackets a dot does not have to be escaped. For example, the expression:
[.]{3}
would match ...
string.
Doesn't it, really? And if so, is it true for all regex standards?
regex standards standards-compliance square-bracket
Yes that is true that DOT (and most other special characters) don't need to be escaped in character class.
– anubhava
Nov 14 '13 at 11:05
2
There is no "standard" for regular expression syntax.
– BoltClock♦
Nov 14 '13 at 11:06
2
@BoltClock there are some: posix, posix extended, perl. See en.wikipedia.org/wiki/Regular_expression#Standards
– Dariusz
Nov 14 '13 at 12:31
1
@Dariusz were you the one who down voted me because you thought I was wrong? if so, I want my 2 points back :)
– Paul Samsotha
Nov 14 '13 at 12:58
@peeskillet yes I was, I stand corrected. Thx and sorry.
– Dariusz
Nov 14 '13 at 13:07
|
show 1 more comment
A dot .
in a regular expression matches any single character. In order for regex to match a dot, the dot has to be escaped: .
It has been pointed out to me that inside square brackets a dot does not have to be escaped. For example, the expression:
[.]{3}
would match ...
string.
Doesn't it, really? And if so, is it true for all regex standards?
regex standards standards-compliance square-bracket
A dot .
in a regular expression matches any single character. In order for regex to match a dot, the dot has to be escaped: .
It has been pointed out to me that inside square brackets a dot does not have to be escaped. For example, the expression:
[.]{3}
would match ...
string.
Doesn't it, really? And if so, is it true for all regex standards?
regex standards standards-compliance square-bracket
regex standards standards-compliance square-bracket
edited May 23 '17 at 12:25
Community♦
11
11
asked Nov 14 '13 at 11:04
DariuszDariusz
15.6k54783
15.6k54783
Yes that is true that DOT (and most other special characters) don't need to be escaped in character class.
– anubhava
Nov 14 '13 at 11:05
2
There is no "standard" for regular expression syntax.
– BoltClock♦
Nov 14 '13 at 11:06
2
@BoltClock there are some: posix, posix extended, perl. See en.wikipedia.org/wiki/Regular_expression#Standards
– Dariusz
Nov 14 '13 at 12:31
1
@Dariusz were you the one who down voted me because you thought I was wrong? if so, I want my 2 points back :)
– Paul Samsotha
Nov 14 '13 at 12:58
@peeskillet yes I was, I stand corrected. Thx and sorry.
– Dariusz
Nov 14 '13 at 13:07
|
show 1 more comment
Yes that is true that DOT (and most other special characters) don't need to be escaped in character class.
– anubhava
Nov 14 '13 at 11:05
2
There is no "standard" for regular expression syntax.
– BoltClock♦
Nov 14 '13 at 11:06
2
@BoltClock there are some: posix, posix extended, perl. See en.wikipedia.org/wiki/Regular_expression#Standards
– Dariusz
Nov 14 '13 at 12:31
1
@Dariusz were you the one who down voted me because you thought I was wrong? if so, I want my 2 points back :)
– Paul Samsotha
Nov 14 '13 at 12:58
@peeskillet yes I was, I stand corrected. Thx and sorry.
– Dariusz
Nov 14 '13 at 13:07
Yes that is true that DOT (and most other special characters) don't need to be escaped in character class.
– anubhava
Nov 14 '13 at 11:05
Yes that is true that DOT (and most other special characters) don't need to be escaped in character class.
– anubhava
Nov 14 '13 at 11:05
2
2
There is no "standard" for regular expression syntax.
– BoltClock♦
Nov 14 '13 at 11:06
There is no "standard" for regular expression syntax.
– BoltClock♦
Nov 14 '13 at 11:06
2
2
@BoltClock there are some: posix, posix extended, perl. See en.wikipedia.org/wiki/Regular_expression#Standards
– Dariusz
Nov 14 '13 at 12:31
@BoltClock there are some: posix, posix extended, perl. See en.wikipedia.org/wiki/Regular_expression#Standards
– Dariusz
Nov 14 '13 at 12:31
1
1
@Dariusz were you the one who down voted me because you thought I was wrong? if so, I want my 2 points back :)
– Paul Samsotha
Nov 14 '13 at 12:58
@Dariusz were you the one who down voted me because you thought I was wrong? if so, I want my 2 points back :)
– Paul Samsotha
Nov 14 '13 at 12:58
@peeskillet yes I was, I stand corrected. Thx and sorry.
– Dariusz
Nov 14 '13 at 13:07
@peeskillet yes I was, I stand corrected. Thx and sorry.
– Dariusz
Nov 14 '13 at 13:07
|
show 1 more comment
1 Answer
1
active
oldest
votes
In a character class (square brackets) any character except ^
, -
, ]
or is a literal.
This website is a brilliant reference and has lots of info on the nuances of different regex flavours.
http://www.regular-expressions.info/refcharclass.html
2
It really depends on how the language handles it, but for most languages this is true.
– Patrick Oscity
Nov 14 '13 at 11:26
26
-
is also literal if it's the last value
– Pedro Lobito
May 10 '16 at 12:38
In ICU and Java regexps, both the[
and]
must be escaped inside a character class (and{
and}
must be escaped outside the character class).
– Wiktor Stribiżew
Oct 11 '16 at 7:03
9
And ^ is literal if it's not the first character
– Nigel Peck
Dec 17 '16 at 2:52
1
If $ looks like a variable, it also needs to be escaped. E.g.: [$.]
– W3Coder
Mar 31 '17 at 13:55
|
show 3 more comments
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
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%2fstackoverflow.com%2fquestions%2f19976018%2fdoes-a-dot-have-to-be-escaped-in-a-character-class-square-brackets-of-a-regula%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
In a character class (square brackets) any character except ^
, -
, ]
or is a literal.
This website is a brilliant reference and has lots of info on the nuances of different regex flavours.
http://www.regular-expressions.info/refcharclass.html
2
It really depends on how the language handles it, but for most languages this is true.
– Patrick Oscity
Nov 14 '13 at 11:26
26
-
is also literal if it's the last value
– Pedro Lobito
May 10 '16 at 12:38
In ICU and Java regexps, both the[
and]
must be escaped inside a character class (and{
and}
must be escaped outside the character class).
– Wiktor Stribiżew
Oct 11 '16 at 7:03
9
And ^ is literal if it's not the first character
– Nigel Peck
Dec 17 '16 at 2:52
1
If $ looks like a variable, it also needs to be escaped. E.g.: [$.]
– W3Coder
Mar 31 '17 at 13:55
|
show 3 more comments
In a character class (square brackets) any character except ^
, -
, ]
or is a literal.
This website is a brilliant reference and has lots of info on the nuances of different regex flavours.
http://www.regular-expressions.info/refcharclass.html
2
It really depends on how the language handles it, but for most languages this is true.
– Patrick Oscity
Nov 14 '13 at 11:26
26
-
is also literal if it's the last value
– Pedro Lobito
May 10 '16 at 12:38
In ICU and Java regexps, both the[
and]
must be escaped inside a character class (and{
and}
must be escaped outside the character class).
– Wiktor Stribiżew
Oct 11 '16 at 7:03
9
And ^ is literal if it's not the first character
– Nigel Peck
Dec 17 '16 at 2:52
1
If $ looks like a variable, it also needs to be escaped. E.g.: [$.]
– W3Coder
Mar 31 '17 at 13:55
|
show 3 more comments
In a character class (square brackets) any character except ^
, -
, ]
or is a literal.
This website is a brilliant reference and has lots of info on the nuances of different regex flavours.
http://www.regular-expressions.info/refcharclass.html
In a character class (square brackets) any character except ^
, -
, ]
or is a literal.
This website is a brilliant reference and has lots of info on the nuances of different regex flavours.
http://www.regular-expressions.info/refcharclass.html
edited Dec 27 '16 at 17:56
MrWhite
12.9k33262
12.9k33262
answered Nov 14 '13 at 11:18
lilactiger89lilactiger89
1,065813
1,065813
2
It really depends on how the language handles it, but for most languages this is true.
– Patrick Oscity
Nov 14 '13 at 11:26
26
-
is also literal if it's the last value
– Pedro Lobito
May 10 '16 at 12:38
In ICU and Java regexps, both the[
and]
must be escaped inside a character class (and{
and}
must be escaped outside the character class).
– Wiktor Stribiżew
Oct 11 '16 at 7:03
9
And ^ is literal if it's not the first character
– Nigel Peck
Dec 17 '16 at 2:52
1
If $ looks like a variable, it also needs to be escaped. E.g.: [$.]
– W3Coder
Mar 31 '17 at 13:55
|
show 3 more comments
2
It really depends on how the language handles it, but for most languages this is true.
– Patrick Oscity
Nov 14 '13 at 11:26
26
-
is also literal if it's the last value
– Pedro Lobito
May 10 '16 at 12:38
In ICU and Java regexps, both the[
and]
must be escaped inside a character class (and{
and}
must be escaped outside the character class).
– Wiktor Stribiżew
Oct 11 '16 at 7:03
9
And ^ is literal if it's not the first character
– Nigel Peck
Dec 17 '16 at 2:52
1
If $ looks like a variable, it also needs to be escaped. E.g.: [$.]
– W3Coder
Mar 31 '17 at 13:55
2
2
It really depends on how the language handles it, but for most languages this is true.
– Patrick Oscity
Nov 14 '13 at 11:26
It really depends on how the language handles it, but for most languages this is true.
– Patrick Oscity
Nov 14 '13 at 11:26
26
26
-
is also literal if it's the last value– Pedro Lobito
May 10 '16 at 12:38
-
is also literal if it's the last value– Pedro Lobito
May 10 '16 at 12:38
In ICU and Java regexps, both the
[
and ]
must be escaped inside a character class (and {
and }
must be escaped outside the character class).– Wiktor Stribiżew
Oct 11 '16 at 7:03
In ICU and Java regexps, both the
[
and ]
must be escaped inside a character class (and {
and }
must be escaped outside the character class).– Wiktor Stribiżew
Oct 11 '16 at 7:03
9
9
And ^ is literal if it's not the first character
– Nigel Peck
Dec 17 '16 at 2:52
And ^ is literal if it's not the first character
– Nigel Peck
Dec 17 '16 at 2:52
1
1
If $ looks like a variable, it also needs to be escaped. E.g.: [$.]
– W3Coder
Mar 31 '17 at 13:55
If $ looks like a variable, it also needs to be escaped. E.g.: [$.]
– W3Coder
Mar 31 '17 at 13:55
|
show 3 more comments
Thanks for contributing an answer to Stack Overflow!
- 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%2fstackoverflow.com%2fquestions%2f19976018%2fdoes-a-dot-have-to-be-escaped-in-a-character-class-square-brackets-of-a-regula%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
Yes that is true that DOT (and most other special characters) don't need to be escaped in character class.
– anubhava
Nov 14 '13 at 11:05
2
There is no "standard" for regular expression syntax.
– BoltClock♦
Nov 14 '13 at 11:06
2
@BoltClock there are some: posix, posix extended, perl. See en.wikipedia.org/wiki/Regular_expression#Standards
– Dariusz
Nov 14 '13 at 12:31
1
@Dariusz were you the one who down voted me because you thought I was wrong? if so, I want my 2 points back :)
– Paul Samsotha
Nov 14 '13 at 12:58
@peeskillet yes I was, I stand corrected. Thx and sorry.
– Dariusz
Nov 14 '13 at 13:07