I'm making a simple Textile parser and am trying to write a regular expression for "blockquote" but am having difficulty matching multiple new lines. Example:
bq. first line of quote second line of quote third line of quote not part of the quote
It will be replaced with blockquote tags via preg_replace()
so basically it needs to match everything between "bq."
and the first double new line it comes across. The best I can manage is to get the first line of the quote. Thanks
This accepted answer only captured the last character of the block for me. I ended up using this:
Edit: Ehr, misread the question.. "bq." was significant.
Sometimes data that is entered via webforms contains \r\n instead of just \n which would make it
The questionmark makes it add the closing blockquotes after the first double return found ("non-greedy" I believe it's called), so any other double returns are left alone (if that is not what you want, take it out obviously).
Try this regex:
meaning:
The
\r?\n
matches a Windows, *nix and (newer) MacOS line breaks. If you need to account for real old Mac computers, add the single\r
to it:\r?\n|\r
Would this work?
I believe 's' stands for single line.
My instincts tell me something like...
Just like the above fella says, the
s
flag after the/
at the end of the RegEx means that the.
will match new line characters. Usually, without this, RegExs are kind of a one line thing.Then the question mark
?
after the.+
denotes a non-greedy match so that the.+
won't match as it can; instead it will match the minimum possible, so that the\n\n
will match the first available double line.To what extent are you planning on supporting features of Textile? Because your RegEx can get pretty complicated, as Textile allows things like...
or...
All of which your regex-replace technique won't be able to handle, methinks.