I'm trying to create a Regular Expression to match "wiki style" lists as in (using preg_replace_callback()
):
* List Item 1
* List Item 2
*# List Item 2.1
*# List Item 2.2
* List Item 3
Asterisks denote Unordered Lists while Number-Signs denote Ordered Lists. I'm trying to get this so it can match infinite dep开发者_高级运维th and so that * and # can be mixed.
I tried the following expression (and variations of it): /\s([\*#]{1,}) ([\S ]+)\s/si
What am I doing wrong? Or is there a better way of accomplishing this?
Try something like this:
\s*([*#]+)\s+.*
Not sure exactly if I understand what you are looking for, but doesn't ([*#]{1,}) ([\S ]+)
work? I think this will give you a match on *
and *#
for group 1 and "List Item 2.1" for group 2, if that is what you are looking for. I know this is essentially what you had, but I am not having any problem with it when testing it out.
Regular expressions are not generally recursive. You need to set up a more traditional parsing approach (perhaps nested state machine using regular expressions to control transitions).
You should check this out:
https://github.com/lahdekorpi/Wiky.php/blob/master/wiky.inc.php
精彩评论