Search, Replace with Regular Expression

  • Thread starter Thread starter lucky
  • Start date Start date
L

lucky

hi there!!

i'm looking for a code snipett wich help me to search some words into a
particular string and replace with a perticular word. i got a huge data
string in which searching traditional way mean to secrife lots of time
in asp.net. can any one give me such a expression in which i pass a
data string and search word string and replace word string? if so plz
help me out. i'm in badly need.
 
lucky said:
i'm looking for a code snipett wich help me to search some words into a
particular string and replace with a perticular word. i got a huge data
string in which searching traditional way mean to secrife lots of time
in asp.net. can any one give me such a expression in which i pass a
data string and search word string and replace word string?

\\\
Imports System.Text.RegularExpressions
..
..
..
Dim s As String = "Hello|Bla|Foo"
Dim t As String = "He said Hello and Bla or Foo"
MsgBox(Regex.Replace(t, s, ""))
///
 
lucky,
Do you want to replace a list of words with a single word, or replace a list
of words with an alternate list of words?

Did you look up RegEx.Replace in the online help?

http://msdn.microsoft.com/library/d...tregularexpressionsregexclassreplacetopic.asp

This topic provides a sample:
http://msdn.microsoft.com/library/d...RegularExpressionsRegexClassReplaceTopic1.asp

Here is an example of replacement patterns:

http://msdn.microsoft.com/library/d...uide/html/cpconexamplechangingdateformats.asp

General information on Regular Expressions:
http://msdn.microsoft.com/library/d...s/cpguide/html/cpconcomregularexpressions.asp

For replacing a list with a list I normally use the overload that accepts a
MatchEvaluator. For replacing a list with a single word I normally use the
overload that accepts a single string. I have not used replacement patterns
yet...



Expresso & RegEx Workbench both have wizards of varying degrees to help you
build your expression, plus they allow you to test your expressions, also
the analyzer/interpreter in each is rather handy.

Expresso:
http://www.ultrapico.com/Expresso.htm

RegEx Workbench:
http://www.gotdotnet.com/Community/...pleGuid=c712f2df-b026-4d58-8961-4ee2729d7322A

tutorial & reference on using regular expressions:
http://www.regular-expressions.info/

The MSDN's documentation on regular expressions:
http://msdn.microsoft.com/library/d...l/cpconRegularExpressionsLanguageElements.asp

Hope this helps
Jay
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top