On Fri, 29 Mar 2013 05:32:52 +0400 Mikhail Kryshen <[email protected]> wrote:
> (re-pattern "a\nb") returns regexp pattern that contains the newline > char literally. > > (re-patter "a\\\nb") returns pattern that contains '\n' (two-char > sequence). ^ should be (re-pattern "a\\nb"). And (re-pattern "a\\\nb") returns pattern that contains '\' followed by the newline char. > These are not the same. '\n' always matches newline, while literal > newline will be ignored if ?x flag is present. > > => (re-matches (re-pattern "(?x)a\\\nb") "a\nb") > "a\nb" Also => (re-matches (re-pattern "(?x)a\\nb") "a\nb") "a\nb" > => (re-matches (re-pattern "(?x)a\nb") "a\nb") > nil > > => (re-matches #"(?x)a\nb" "a\nb") > "a\nb" > > => (re-matches #"(?x)a > b" "a\nb") > nil > > > On Thu, 28 Mar 2013 17:08:46 -0700 > Mark Engelberg <[email protected]> wrote: > > > I'm in reader hell right now, trying to puzzle out how escape sequences and > > printing work for strings and regular expressions. > > > > I notice that: > > (re-pattern "a\nb") > > (re-pattern "a\\nb") > > (re-pattern "a\\\nb") > > > > all produce semantically equivalent regular expressions that match "a\nb" > > > > The middle one prints the way I'd expect, as #"a\nb" > > > > However, the first and last example print as: > > #"a > > b" > > > > Even weirder, printing it with pr has no effect, and it still prints as: > > #"a > > b" > > > > I can sort of imagine why the middle one (re-pattern "a\\nb") might be > > stored internally in a somewhat different format than the other two, but I > > really can't figure out why the "machine-oriented print" of pr would still > > print the blank line rather than \n in this context. > > > > Bug or feature? > > > > Can anyone point me to the relevant code where I can get a better > > understanding of how the reading and printing of regexps differs from > > strings? > > > > --Mark > > -- Mikhail -- -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to [email protected] Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.
