Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

RegExp to match several lines 3

Status
Not open for further replies.

Rydel

Programmer
Feb 5, 2001
376
CZ
I apologize if it's a sort of beginning question, but I couldn't find that in the help file (or figure it out myself for that matter). I'd like to match all blackquotes inside an HTML file. E.g. <blockquote>any text</blockquote>. I constructed the following Regular expression:
regEx.Pattern = &quot;<blockquote>.*<\/blockquote>&quot;
Unfortunately .* does not include new line character, so only when both tags are on the same line I get what I want. Otherwise - niente. Any gurus who could give a hand to a novice? :)
---
---
 
rydel,

does regexp.global=true not work for you? I think it should treat a string with returns as a string with none. From what I've seen, it does. In perl, the . works the same way, matching all characters expect newline. But you can set a condition with 's' to let it match newlines.

$string=m/.*/s;

But I can't find a vbscript version of that.
I tried &quot;.*&quot;s but I got a syntax error. The only thing I can think is to just use .global=true. Sorry I couldn't be of more help.

Mike
 
motte is right in that global is what you need.

fyi - .* (non-greedy regexp) is only supported in VBScript 5.5... make sure that your web server is running it.

ex:
dim re
set re = new regexp
re.global = true 'affects everything
re.ignorecase = true 'guess what this does :)
re.pattern = &quot;<.*>&quot; 'this searches for anything in <> tags
...

you get the idea.

hth ---------
Leo Mendoza
lmendoza@students.depaul.edu
 
vasah20,

Just to let you know, .* is very greedy. It grabs anything, including that closing >. It looks for anything. To make it non-greedy, you need <.*?>. That ? will stop the greed search. Or you can just do <[^>]*>. That means anything not the closing >.

Mike
 
thank you very much! it was just what i needed :)
the question of &quot;greediness&quot; (whether it grabs the smallest or the biggest possible) is also intersting to me. could you tell me what option sets that or where I can read more about it. because with the current set up i will get
<blockqoute>quote1</blockquote>
trash
<blockquote>quote2</blockquote>

all of it, instead of getting two bloackquotes separately.

---
---
 
thanks motte... i knew it looked funny when I typed it... you get a star for catching my error ;)

rydel -
you want the non-greedy matches, because with the non-greedy matches, it will always stop at first match.

for instance
<b>some text</b>

with the greedy, VBScript doesn't know whether or not to stop at the end of the <b> tag or the </b> tag, since both have the > character. With the non-greedy, it always stops at the first match, so the <b> tag is found.

hth
leo ---------
Leo Mendoza
lmendoza@students.depaul.edu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top