CArNi4
09-11-2003, 10:56 AM
Hi, I'm a newbie when it comes to regular expressions, after experimenting a bit I tried to use them to colorize HTML. I got that to work but now I want to colorize the text within quotes, like this:
<img src="picture.gif" width="100" height="100">
The parts "picture.gif", "100" and "100" should be in another color but since width= is between two "'s it also gets colorized. What regular expression should I use to get this to work?
P.S. Visual Basic 6.0, Microsoft VBScript Regular Expressions 5.5
Thinker
09-13-2003, 09:34 AM
I don't see anywhere in your posts where you mention the particular
regular expression you have been using. I don't have time to figure them
out from the start but I have been able to help people refine them at
times.
CArNi4
09-13-2003, 11:05 AM
I don't see anywhere in your posts where you mention the particular
regular expression you have been using. I don't have time to figure them
out from the start but I have been able to help people refine them at
times.
The pattern I use to get all the tags in a MatchCollection is (<[^\?<>\n\t]+>), once I've executed it I loop through the MatchCollection. Then everything matching the pattern (""[^\n\\]+""|'[^\n\\]+') is replaced by the colorized text.
I've been trying a lot of different regular expressions for this but none of them worked.
Thinker
09-13-2003, 03:35 PM
What are you using to replace what is returned from the second match?
I can't do a match that doesn't return the " or ' because they are what
indicated the unique values to return. I can return all the " and '
delimited parameters with ("|')(.{1,}?)\1 (of course this won't work for
ones that have no delimiters). But it will still have the " or ' as part of
the matchcollection value. It is easy enough to use the normal VB string
handling functions to work around them.
CArNi4
09-13-2003, 05:21 PM
I've got the right regular expression now(I guess):
RegExp.Pattern = "=""(.*?)""\s|=""(.*?)""\>"
Thinker
09-13-2003, 06:53 PM
The only thing I can match with that expression is src="picture1.gif". It
doesn't match src='picture1.gif' or width=100. On top of that, it includes
the = in the match. I sure wish I knew how you were using it.
CArNi4
09-14-2003, 02:37 AM
You're right, I tested this regular expression by just executing it and checking all the matches, but excluding = in the match and adding ' won't be a problem.