In perl when matching multi-line strings you can add the s modifier /.../s that will change the semantics of . to match also newline. Is there something similar for string-match? Or is there a workaround?

  • Are you asking for a way to convert regular expressions that have . to additionally match new lines or how to match any character including newline in general? – Aquaactress Oct 12 '19 at 19:54
  • 2
    FWIW, I asked that this ability be added to Elisp regexps long ago: 1 and 2. Went nowhere... – Drew Oct 12 '19 at 23:37
  • @Drew: For the perl m modifier I can used instead of ^ and $ the escaped `` \` `` and `` \' `` (hard to write in markdown). But for . it doesnt seem to exist. Feels indeed like something that would be helpful if added. Phils answer below does work. I tried before with [[:asci:][:nonascii]] but stangely that failes if there is a unicode sequence embedded in the textstream anyway. – Konrad Eisele Oct 13 '19 at 6:28
  • Yes, @phils's answer is what we have to do (and have always had to do): specify "either a newline char or a char other than newline". My comment was to point out that I think Elisp regexps should offer a short way of specifying that. – Drew Oct 13 '19 at 14:58

No, you can't make . match newlines; you have to simply state what you want to match. e.g.: "\\(?:.\\|\n\\)"

However if you use rx to generate your regexp, then note that it provides distinct symbols for the two cases:

`not-newline', `nonl'
     matches any character except a newline.

     matches any character


(rx "foo" anything "bar")
=> "foo\\(?:.\\|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.