pr0pensity
[H]ard|Gawd
- Joined
- Sep 2, 2003
- Messages
- 1,738
I'm reading up on this, but I don't quite get the syntax. How would I parse [b] [/b] tags or replace all ascii characters from 0 to 31 with a space?
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
ameoba said:While generally adequate, REs aren't really up to the job of parsing HTML (or HTML-like markup such as vB-code) where you can legally nest things to arbitrary depths. Basic CS stuff - REs are not powerful enough to handle CFGs.
tim_m said:^^ that only finds the tags, it doesn't replace them. then again, the OP never specified what language was being used
(?<=\[b\]).*?(?=\[/b\]) for what was in original posting
will find the 'b' tags.
tim_m said:you said it yourself
as i said, you're using a look behind and look ahead assertion to ensure that the <b> and </b> are there. this only lets you know that there is a <b> and </b> in the string somewhere if the regex matches. you need some sort of regex replace to find [ b] and [/b ] and replace them with <b> and </b>
as for a 'real' parser, the way it works is with a stack or two and lots of black magic
an example:
http://www.christian-seiler.de/projekte/php/bbcode/index_en.html