Using regular expressions via `re-search-forward` in elisp [duplicate]











up vote
0
down vote

favorite













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?



enter image description hereenter image description here










share|improve this question













marked as duplicate by phils elisp
Users with the  elisp badge can single-handedly close elisp questions as duplicates and reopen them as needed.

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 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.



















    up vote
    0
    down vote

    favorite













    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?



    enter image description hereenter image description here










    share|improve this question













    marked as duplicate by phils elisp
    Users with the  elisp badge can single-handedly close elisp questions as duplicates and reopen them as needed.

    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 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.

















      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite












      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?



      enter image description hereenter image description here










      share|improve this question














      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?



      enter image description hereenter image description here





      This question already has an answer here:




      • Emacs - regular expressions in Lisp need to be double-escaped - why?

        4 answers








      elisp






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 18 at 2:51









      smilingbuddha

      5,4362183140




      5,4362183140




      marked as duplicate by phils elisp
      Users with the  elisp badge can single-handedly close elisp questions as duplicates and reopen them as needed.

      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 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 elisp
      Users with the  elisp badge can single-handedly close elisp questions as duplicates and reopen them as needed.

      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 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.


























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          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.






          share|improve this answer





















          • 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
            yesterday


















          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          0
          down vote













          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.






          share|improve this answer





















          • 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
            yesterday















          up vote
          0
          down vote













          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.






          share|improve this answer





















          • 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
            yesterday













          up vote
          0
          down vote










          up vote
          0
          down vote









          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.






          share|improve this answer












          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.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 18 at 5:33









          phils

          57.1k7107140




          57.1k7107140












          • 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
            yesterday


















          • 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
            yesterday
















          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
          yesterday




          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
          yesterday



          Popular posts from this blog

          If I really need a card on my start hand, how many mulligans make sense? [duplicate]

          Alcedinidae

          Can an atomic nucleus contain both particles and antiparticles? [duplicate]