Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

6
  • 2
    You seem to have misunderstood the question: it's to match names that may contain a newline, not match that must contain a newline. With GNU find, find -regex '.*' does not match file names containing newlines. Commented Sep 1, 2021 at 20:35
  • @Gilles'SO-stopbeingevil' Thanks. Updated. Commented Sep 1, 2021 at 20:38
  • The updated answer works for the specific toy example in the question, but isn't generalizable to any other case. Commented Sep 1, 2021 at 20:40
  • @Gilles'SO-stopbeingevil' It's difficult to see what cases they need covered and what doesn't work. It's a literal solution to their actual question. Commented Sep 1, 2021 at 20:42
  • @Kusalananda, they're asking "how to write the regex so that [it] will match newlines", and mentioning (?s) and .../s, both of which are ways in Perl for enabling the s option to the regex. By default, the . in Perl doesn't match newlines, but with the s option it does. Try e.g. perl -e 'print "yes\n" if "foo\nbar" =~ /foo.bar/' vs. =~ /foo.bar/s or =~ /(?s)foo.bar/' Commented Sep 1, 2021 at 20:53