bobbit31
asked on
RegEx to implement BBCode style quoting in a forum post
hello experts,
I need a regular expression that will match something like the following:
-------------------------- ---------- ---------- --------
[quote name='some name' date='some date']
This is what is being quoted.
[/quote]
-------------------------- ---------- ---------- --------
this should also support nested quotes, such as:
-------------------------- ---------- ---------- --------
[quote name='some name' date='some date']
[quote name='other name' date='other date']
This is a nested quote.
[/quote]
this is the original quote.
[/quote]
-------------------------- ---------- ---------- --------
the quote doesn't necessarily have to be the first thing either... there can be text both before and after.
if possible, i'd like to make the name and date attributes optional (as in, they don't have to be there).
it's important that it matches both the opening and closing tag as i'm going to be replacing it with divs and if you leave out the [/quote] it will end up breaking the layout.
Thank you, your help is greatly appreciated!
I need a regular expression that will match something like the following:
--------------------------
[quote name='some name' date='some date']
This is what is being quoted.
[/quote]
--------------------------
this should also support nested quotes, such as:
--------------------------
[quote name='some name' date='some date']
[quote name='other name' date='other date']
This is a nested quote.
[/quote]
this is the original quote.
[/quote]
--------------------------
the quote doesn't necessarily have to be the first thing either... there can be text both before and after.
if possible, i'd like to make the name and date attributes optional (as in, they don't have to be there).
it's important that it matches both the opening and closing tag as i'm going to be replacing it with divs and if you leave out the [/quote] it will end up breaking the layout.
Thank you, your help is greatly appreciated!
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
is close, however, the match data comes up wrong:
example:
[quote name='b' date='n']test1[quote name='c' date='m']test2[/quote]this
$1 is:
name='b' date='n']test1[quote name='c' date='m'
Also, i need to know what is b/w the quote tags... so something like this?
var r = /.*\[quote( name=('|").*('|"))?( date=('|").*('|"))?\](.*)?
when i do that, $3 is:
b' date='n']test1[quote name='c' date='m'