Link to home
Start Free TrialLog in
Avatar of hankknight
hankknightFlag for Canada

asked on

ASP.NET / VB / REGEX: Test for match instead of replace

The code below replaces matches inside a string.  Instead of replacing all matches inside the string, I want the entire string to be replaced if there is a match.

The string should become empty if there is no match and it should contain the full word if there is a match.

Please test this:
<%@ Page Language="VB" AutoEventWireup="false" %>
<% 
Dim str As String

str = "in is a state in America near Michigin"
str = RegularExpressions.Regex.Replace(str, "(?i)\bin\b", "Indiana")
Response.Write(str)
' Should return "Indiana"

Response.Write("<hr />")

str = "Testing 123"
str = RegularExpressions.Regex.Replace(str, "(?i)\bin\b", "Indiana")
Response.Write(str)
' Should not return anything

%>

Open in new window

SOLUTION
Avatar of DustinKikuchi
DustinKikuchi
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial