开发者

How does wikimedia transform its model syntax?

I would like to know how does Wikimedia transform its model syntax ({{model|options}}) into html code. I have a regex for a si开发者_JS百科mple model ({{.*?}}) but it fails for a nested model (ex: {{model|options containing a {{submodel|options}}...}})


Remember,

Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems. - Jamie Zawinski

That said, you can read: Forum tags. What is the best way to implement them? I made an example of nested tags, both with "pure" Regex and with a "more stable" C# parser that uses a little of Regexes but keeps the stack out of the Regex hands.

You can do it with balancing groups. They aren't part of "base" Regex (and some persons don't consider them to be true regexes),

But I wouldn't program something as big as Wiki with something like a regex. The problem of regexes is that it's quite difficult to program them so that they don't backtrack (there is an option to do it, but it's difficult to build a regex that doesn't need backtracking or that need only limited amout of backtracking), and when they begin to backtrack it's the end: they could stall for minutes searching for the right combination of captures.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜