RegExp with crlf?

Posted on 2005-03-24
Medium Priority
Last Modified: 2009-12-16

TestString = "[quote=Blah]Test" & vbCrLf & "Test[/quote]"

Set r = New RegExp
r.pattern = "\[QUOTE=(.*?)\](.*?)\[/QUOTE\]"
r.global = true
r.ignorecase = True
tmpRet = TestString

  RunRegExp = tmpRet
  tmpRet = r.replace(tmpRet, "<table border=""0"" width=""90%"" align=""center""><tr><td>&nbsp;<b>Quote </b>&nbsp;from $1</td></tr><tr><td><div class=""quote"">$2</div></td></tr></table>")
Loop Until RunRegExp = tmpRet

Set r = Nothing

Response.Write RunRegExp


so the pattern as you can see is:"\[QUOTE=(.*?)\](.*?)\[/QUOTE\]"
and if I have a crlf in the string it does not work ... what do I have to change the pattern to, to make this work?
Question by:ThaSmartUno
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2

Accepted Solution

dmenard earned 2000 total points
ID: 13628633

The dot matches any character, except "\n".

I write it from memory (can't test just now), but the following may work...

Try replacing every dot in yout regexp with (.|\n) :

Or, even better, use a non capturing group (?:.|\n), so it won't interfere with what you already capture :
LVL 10

Author Comment

ID: 13629766
now what would be different using the second one?

because they both work ... (i could have sworn i tried the first one, probably used []'s instead of ()'s)  

Expert Comment

ID: 13629988
The syntax (xxx) means a capturing match : everything between the parenthesis will be captured by the regexp engine, so you can use it later in the Matches collection or in a replacement.

The syntax (?:xxx) means a non capturing match : the parenthesis are just used to group something (. and \n in our case).

A non capturing match is more efficient (the engine do not need to store anything)

And least, as your pattern already contain capturing matches, I thought it would be best to not change the order of your captures :

In your original pattern : \[QUOTE=(.*?)\](.*?)\[/QUOTE\]
capture #1=what follow "="
capture #2=what is between ] and [

with the first syntax I proposed, capture #2 would become capture #3 or #4, with the second one, their order is unchanged.

so, use the second one : no change in the order and more efficient.
LVL 10

Author Comment

ID: 13629999
Oh i see ... thank you

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question