regexp question

  • Thread starter Bart van den Burg
  • Start date
B

Bart van den Burg

Hi

I have the following regexp:
$message =~ s/\[quote ?([^\]]*)](.*)\[\/quote]/<DIV STYLE='border: 1px solid
black; padding: 2px; margin: 2px'>Quote $1:<DIV STYLE='font-size: .9em;
color: #444444; margin-left: 5px;'>$2<\/DIV><\/DIV>/;

It works on the following:[/QUOTE] ja ach...
----------------------------------------------------

But not on this:
----------------------------------------------------
[quote Bart][...]

test[/quote]

TEST!!!
----------------------------------------------------

What am I forgetting/doing wrong?

Thanks
Bart
 
G

Gunnar Hjalmarsson

Bart said:
I have the following regexp:
$message =~ s/\[quote ?([^\]]*)](.*)\[\/quote]/<DIV STYLE='border: 1px solid
black; padding: 2px; margin: 2px'>Quote $1:<DIV STYLE='font-size: .9em;
color: #444444; margin-left: 5px;'>$2<\/DIV><\/DIV>/;

It works on the following:
ja ach...
----------------------------------------------------

But not on this:
----------------------------------------------------
[quote Bart][...]

test[/quote]

TEST!!![/QUOTE]

You are forgetting the /s modifier.

If there are more than one such sections in the text
you are applying the regexp to, you'd better make it non-greedy and
add the /g modifier:

s/\[quote ?([^\]]*)](.*?)\[\/quote]/.../gs;
---------------------------^----------------^^
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,007
Latest member
obedient dusk

Latest Threads

Top