Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

RegExp with crlf?

Posted on 2005-03-24
4
Medium Priority
?
583 Views
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

do
  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?
0
Comment
Question by:ThaSmartUno
  • 2
  • 2
4 Comments
 
LVL 2

Accepted Solution

by:
dmenard earned 2000 total points
ID: 13628633
Hello,

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) :
"\[QUOTE=((.|\n)*?)\]((.|\n)*?)\[/QUOTE\]"

Or, even better, use a non capturing group (?:.|\n), so it won't interfere with what you already capture :
"\[QUOTE=((?:.|\n)*?)\]((?:.|\n)*?)\[/QUOTE\]"
0
 
LVL 10

Author Comment

by:ThaSmartUno
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)  
0
 
LVL 2

Expert Comment

by:dmenard
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.
0
 
LVL 10

Author Comment

by:ThaSmartUno
ID: 13629999
Oh i see ... thank you
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…

581 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