Using regular expressions via `re-search-forward` in elisp [duplicate]
This question already has an answer here:
Emacs - regular expressions in Lisp need to be double-escaped - why?
4 answers
I want to search for an regular expression with the function re-search-forward
When I tried using the examples from the page
here: https://www.emacswiki.org/emacs/RegularExpression#toc1
specifically the regular expression w{20,}
used to search for a word with 20 letters or more, I get an error.
Here I am placing my cursor after the closing parenthesis in my Lisp buffer and pressing C-x C-e
for evaluating it.
However, when I use the Regexp I-search via,
C-M-s
it highlights the correct word as expected.
Why is this?
elisp
marked as duplicate by phils
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 18 '18 at 5:35
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
Emacs - regular expressions in Lisp need to be double-escaped - why?
4 answers
I want to search for an regular expression with the function re-search-forward
When I tried using the examples from the page
here: https://www.emacswiki.org/emacs/RegularExpression#toc1
specifically the regular expression w{20,}
used to search for a word with 20 letters or more, I get an error.
Here I am placing my cursor after the closing parenthesis in my Lisp buffer and pressing C-x C-e
for evaluating it.
However, when I use the Regexp I-search via,
C-M-s
it highlights the correct word as expected.
Why is this?
elisp
marked as duplicate by phils
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 18 '18 at 5:35
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
Emacs - regular expressions in Lisp need to be double-escaped - why?
4 answers
I want to search for an regular expression with the function re-search-forward
When I tried using the examples from the page
here: https://www.emacswiki.org/emacs/RegularExpression#toc1
specifically the regular expression w{20,}
used to search for a word with 20 letters or more, I get an error.
Here I am placing my cursor after the closing parenthesis in my Lisp buffer and pressing C-x C-e
for evaluating it.
However, when I use the Regexp I-search via,
C-M-s
it highlights the correct word as expected.
Why is this?
elisp
This question already has an answer here:
Emacs - regular expressions in Lisp need to be double-escaped - why?
4 answers
I want to search for an regular expression with the function re-search-forward
When I tried using the examples from the page
here: https://www.emacswiki.org/emacs/RegularExpression#toc1
specifically the regular expression w{20,}
used to search for a word with 20 letters or more, I get an error.
Here I am placing my cursor after the closing parenthesis in my Lisp buffer and pressing C-x C-e
for evaluating it.
However, when I use the Regexp I-search via,
C-M-s
it highlights the correct word as expected.
Why is this?
This question already has an answer here:
Emacs - regular expressions in Lisp need to be double-escaped - why?
4 answers
elisp
elisp
asked Nov 18 '18 at 2:51
smilingbuddhasmilingbuddha
5,5072184142
5,5072184142
marked as duplicate by phils
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 18 '18 at 5:35
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by phils
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 18 '18 at 5:35
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
This regexp:
w{20,}
is expressed in a double-quoted elisp string like so:
"\w\{20,\}"
Backslashes are special to the double-quoted read syntax for strings as well as being special to regexp syntax; so if a backslash is for the regexp, you need to double it.
Notice also how, in the screenshots in the question, the incorrect singular backslashes are coloured red? That is Emacs (26+) telling you that they are probably a mistake.
– phils
Nov 23 '18 at 22:29
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
This regexp:
w{20,}
is expressed in a double-quoted elisp string like so:
"\w\{20,\}"
Backslashes are special to the double-quoted read syntax for strings as well as being special to regexp syntax; so if a backslash is for the regexp, you need to double it.
Notice also how, in the screenshots in the question, the incorrect singular backslashes are coloured red? That is Emacs (26+) telling you that they are probably a mistake.
– phils
Nov 23 '18 at 22:29
add a comment |
This regexp:
w{20,}
is expressed in a double-quoted elisp string like so:
"\w\{20,\}"
Backslashes are special to the double-quoted read syntax for strings as well as being special to regexp syntax; so if a backslash is for the regexp, you need to double it.
Notice also how, in the screenshots in the question, the incorrect singular backslashes are coloured red? That is Emacs (26+) telling you that they are probably a mistake.
– phils
Nov 23 '18 at 22:29
add a comment |
This regexp:
w{20,}
is expressed in a double-quoted elisp string like so:
"\w\{20,\}"
Backslashes are special to the double-quoted read syntax for strings as well as being special to regexp syntax; so if a backslash is for the regexp, you need to double it.
This regexp:
w{20,}
is expressed in a double-quoted elisp string like so:
"\w\{20,\}"
Backslashes are special to the double-quoted read syntax for strings as well as being special to regexp syntax; so if a backslash is for the regexp, you need to double it.
answered Nov 18 '18 at 5:33
philsphils
57.8k7109142
57.8k7109142
Notice also how, in the screenshots in the question, the incorrect singular backslashes are coloured red? That is Emacs (26+) telling you that they are probably a mistake.
– phils
Nov 23 '18 at 22:29
add a comment |
Notice also how, in the screenshots in the question, the incorrect singular backslashes are coloured red? That is Emacs (26+) telling you that they are probably a mistake.
– phils
Nov 23 '18 at 22:29
Notice also how, in the screenshots in the question, the incorrect singular backslashes are coloured red? That is Emacs (26+) telling you that they are probably a mistake.
– phils
Nov 23 '18 at 22:29
Notice also how, in the screenshots in the question, the incorrect singular backslashes are coloured red? That is Emacs (26+) telling you that they are probably a mistake.
– phils
Nov 23 '18 at 22:29
add a comment |