|
-
Jun 6th, 2002, 11:13 AM
#1
Thread Starter
Frenzied Member
RegEx in VBScript
With this ASP:
Code:
<% @Language="VBScript" %>
<%
Option Explicit
Dim strTestOne
strTestOne = "Blah"
Dim strTestTwo
strTestTwo = "Blah yadda yadda yadda Blah"
Dim strResultOne, strResultTwo
Dim objRegEx
Set objRegEx = New regexp
objRegEx.IgnoreCase = True
objRegEx.Global = True
objRegEx.Pattern = "\[url=""(.+)""\](.+)\[\/url\]"
strResultOne = objRegEx.Replace(strTestOne, "<a href=""\1"">\2</a>")
strResultTwo = objRegEx.Replace(strTestTwo, "<a href=""\1"">\2</a>")
%>
<html>
<head>
<title>VBScript RegEx Test</title>
</head>
<body>
<p>Test string: <%=strTestOne%></p>
<p>Result string: <%=strResultOne%></p>
<p>Test string: <%=strTestTwo%></p>
<p>Result string: <%=strResultTwo%></p>
<p>Pattern: <%=objRegEx.Pattern%></p>
</body>
</html>
[/code]
I get these reults:
[code]
<html>
<head>
<title>VBScript RegEx Test</title>
</head>
<body>
<p>Test string: [vrl="http://www.foo.com/bar.html"]Blah[/vrl]</p>
<p>Result string: <a href="\1">\2</a></p>
<p>Test string: [vrl="http://www.foo.com/bar.html"]Blah[/vrl] yadda yadda yadda [vrl="http://www.foo.com/bar.html"]Blah[/vrl]</p>
<p>Result string: <a href="\1">\2</a></p>
<p>Pattern: \[url="(.+)"\](.+)\[\/url\]</p>
</body>
</html>
This isn't working at all. Any help?
Note: "url" changed to "vrl" in some places in the response code to get past vBulletin.
Travis, Kung Foo Journeyman
As always, RTFM.
WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
YBMS, but Mozilla doesn't.
-
Jun 6th, 2002, 11:15 AM
#2
Black Cat
Use $ instead of \.
VB Code:
Dim re As VBScript_RegExp_55.RegExp
Set re = New VBScript_RegExp_55.RegExp
re.Pattern = "^(\d{5})(\d{5})$"
Debug.Print re.Replace("1111122222", "$2$1")
Set re = Nothing
Josh
Get these: Mozilla Opera OpenBSD
I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.
-
Jun 6th, 2002, 11:18 AM
#3
Thread Starter
Frenzied Member
$ works, thanks. That is contrary to the documentation at MSDN, but is more of what I would expect.
Now, how do I get it to replace each instance and not the entire line?
Travis, Kung Foo Journeyman
As always, RTFM.
WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
YBMS, but Mozilla doesn't.
-
Jun 10th, 2002, 11:24 AM
#4
Thread Starter
Frenzied Member
Any ideas? I still can't get this RegEx to work consitently.
Travis, Kung Foo Journeyman
As always, RTFM.
WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
YBMS, but Mozilla doesn't.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|