Regex BBCode to HTML

前端 未结 2 1078
误落风尘
误落风尘 2021-01-22 00:17

I writing BBcode converter to html.
Converter should skip unclosed tags.

I thought about 2 options to do it:
1) match all tags in once using one regex call, like

2条回答
  •  暖寄归人
    2021-01-22 00:49

    One option would be to use more SAX-like parsing, where instead of looking for a particular regex you look for [, then have your program handle that even in some manner, look for the ], handle that even, etc. Although more verbose than the regex it may be easier to understand, and wouldn't necessarily be slower.

提交回复
热议问题