-1

I have a simple regex:

\[quote\](.*?)\[\/quote\]

Which will replace [quote] by table, tr and td. (and [/quote] by /td, /tr and /table)

It works perfectly for multiple separate quotes in the same string:

IE:

[quote]
Person 1
[/quote]
Person 3 talking about a quote

[quote]
Person 2
[/quote]
Person 3 talking about another quote.

But when it tries to replace multiple (non-separate) quote in the same string:

IE:

[quote]
[quote]
Person 1
[/quote]
Person 2 quoting person 1
[/quote]
Person 3 quoting person 2 and 1

It messes up, (matches the first quote to the first /quote when it should be matching second quote to first /quote and first quote to last /quote)

How would I edit the regex so it works in both examples?

2
  • One cell tables? I thought we'd given up on those around 2000AD. :( Commented Sep 23, 2011 at 12:54
  • 2
    Per the accepted answer, this question can be regarded as a dup of: Any good javascript BBCode parser? Commented Oct 19, 2023 at 22:24

3 Answers 3

2

Regex isn't a good choice for parsing nested structured text. See this question for JavaScript BBCode parser

Sign up to request clarification or add additional context in comments.

1 Comment

I'm using Javascript :( (preview post box)
0

Try this one:

\[quote\]{1,}(.*?)\[\/quote\]

1 Comment

Did you mean a quote sign or the literal [quote] (as string)?
0

I created an example JavaScript BBCode parser that handles that situation. I think I got around that situation because JavaScript's string replace function can take in another function, so you can make your parser recursively work with smaller sections of the input. However, it's been a while since I've looked at it. You can see it in action here and download it on the same page (the download link is under the header - "You can download the JavaScript module for this here."):

http://patorjk.com/bbcode-previewer/

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.