You are not logged in.

#1 2008-10-07 13:12:23

xelados
Member
Registered: 2007-06-02
Posts: 314
Website

Can't seem to figure out the magic regex (PHP)

http://pastebin.com/m1d965a85

What I want is to wrap all the highlighted lines (except the regex rule on line 53 tongue) with "<p>" and </p>". Unfortunately, every regex I've tried to get to work on it hasn't done what I needed to. It would either wrap the whole page (even with the "U" option enabled), wrap every letter, or every word.

The goal is to match any line (or series of lines) that doesn't have any special markup around it and has an empty line above and below it. For example...


This:

(blank line)\n
Yay for paragraphs.\n
(blank line)

Would become this:

<p>
Yay for paragraphs.
</p>

That's all I want it to do.. I've read up on regular expressions on regex.info, consulted the guys at Freenode's #php, and also the guys at #regex. Unfortunately I wasn't able to get any meaningful help. For example, someone at #regex suggested that I use an HTML parser, which makes no sense because I'm only outputting HTML, not accepting it as input. Any help I could receive with this would be greatly appreciated. I've been wracking my brain over it for hours..

Last edited by xelados (2008-10-07 13:13:04)

Offline

#2 2008-10-07 16:25:44

pointone
Wiki Admin
From: Waterloo, ON
Registered: 2008-02-21
Posts: 379

Re: Can't seem to figure out the magic regex (PHP)

Not sure about PHP, but in Python I can use something like "^\n$". I've seen people use "^$" to match blank lines before, too...


M*cr*s*ft: Who needs quality when you have marketing?

Offline

#3 2008-10-08 01:50:41

xelados
Member
Registered: 2007-06-02
Posts: 314
Website

Re: Can't seem to figure out the magic regex (PHP)

That doesn't seem to work, either... How do sources like MediaWiki, DokuWiki, or even Wordpress do theirs?

EDIT: I've decided to skip this part of my project for now. After some reading on wikipedia it seems that I need to setup a finite state machine of some sort, a lexer to create tokens, and then replace those with appropriate output. It'll probably be the most time consuming part, so I'll save it for last.

Last edited by xelados (2008-10-08 03:52:58)

Offline

Board footer

Powered by FluxBB