0

In an Elisp regexp, when I want to specify a pattern across two consecutive lines, I found that ^J^.* (^J is new line, and ^ is anchor of the beginning of a line) doesn't work, but ^J.* works. I was wondering why? (Is it also the case in other flavor of regex, such as the one used in Python?)

2
  • There's confusion in the way your question is written. Presumably, when you wrote ^J you meant the single character Control-J (aka newline), and not the two characters ^ and J. But when you wrote ^.* I'm guessing you meant the three characters ^, ., and *.
    – Drew
    Oct 20, 2023 at 16:59
  • Please one question per question. Also, please do not ask Python questions on Emacs SE: SO is the proper place.
    – NickD
    Oct 21, 2023 at 17:07

1 Answer 1

2

The answer can be found in the Gnu Manual:

^ is a special character that matches the empty string, but only at the beginning of a line in the text being matched [...]

For historical compatibility reasons, ^ can be used with this meaning only at the beginning of the regular expression, or after \( or \|.

2
  • 1
    thanks. Is it also the case in other implementations of the same flavor as in Emacs, and in implementations of other flavors of regex, such as the one used in Python?
    – Tim
    Oct 20, 2023 at 12:54
  • Please do not ask additional questions in comments. Ask a new question - except that in this case, the question is way too general. You can ask the particular question about the Python regex engine on SO, but otherwise, the question is too open-ended as it stands.
    – NickD
    Oct 21, 2023 at 17:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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