string/replace regex help

93 views
Skip to first unread message

Kuba Roth

unread,
Jan 16, 2014, 4:02:58 PM1/16/14
to clo...@googlegroups.com
Hi,
This is more of a regex specific question the clojure, but anyway...
I have the a multiline string as follow:
(def myText "aaaaaSTART
bbbb
cccc
END
eeeeee
ff
ggg
START
hhhhhhhh
ii               E
jjjj
END
kkkkkkkk
llll")


.. and I need to replace all text between START END 'keywords' blocks.
The following regex:
(clojure.string/replace myText #"START([^END])*" "======")

does sort of what I'm hoping to get but does not guard me against cases when one of the "END" (in this case          E)   characters shows up in the middle of the block to be cut.
So my question comes down to what am I missing here? :)

Any suggestions are highly appreciated.
Thanks,
kuba

John Wiseman

unread,
Jan 16, 2014, 4:16:28 PM1/16/14
to clo...@googlegroups.com
(clojure.string/replace myText #"(?s)START.*?END" "======")
;; "aaaaa======\neeeeee\nff\nggg\n======\nkkkkkkkk\nllll"

(?s) specifies multi-line mode, *? is the non-greedy form of *.


--
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@googlegroups.com
Note that posts from new members are moderated - please be patient with your first post.
To unsubscribe from this group, send email to
clojure+u...@googlegroups.com
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 clojure+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Kuba Roth

unread,
Jan 16, 2014, 4:43:07 PM1/16/14
to clo...@googlegroups.com
Sweet! Thanks so much!
You received this message because you are subscribed to a topic in the Google Groups "Clojure" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/clojure/VOz4piaP5mE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to clojure+u...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages