ASP.NET / VB / REGEX: Replace "at" but not "cat" or "ate"

Posted on 2012-09-18
Medium Priority
Last Modified: 2012-09-18
Using ASP.NET, VB and Regular Expressions, how can I replace "at" but only if it is the entire word?  I want "AT" to be replaced if is the entire word but I do not want the "at" inside of "cat" to be replaced.

<%@ Page Language="VB" AutoEventWireup="false" %>
Dim str As String = "At bat fat at cat at"
str = RegularExpressions.Regex.Replace(str, "at", "***")
' Should be "*** bat fat *** cat ***"

Open in new window

Question by:hankknight
  • 2
LVL 35

Expert Comment

ID: 38409334
LVL 35

Accepted Solution

YZlat earned 2000 total points
ID: 38409343
Dim input As String = "replace word at but not on cat"
Dim pattern As String = "\bat\b"
Dim replace As String = ""
Dim result As String = Regex.Replace(input, pattern, replace)

Open in new window


Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Suggested Courses
Course of the Month8 days, 19 hours left to enroll

621 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