.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Replace space from string - REGEX.

Posted By:      Posted Date: September 27, 2010    Points: 0   Category :ASP.Net


I have some problem with RegEx.

I have text:

"something here [tagQuote=Name of Author]bla bla bla[/tagQuote] something here"

And now I want to replace all the whitespace character in quote attribute with "%#%#%#%".

So I want to have: [tagQuote=Name%#%#%#%of%#%#%#%Author]bla bla bla[/tagQuote]

So remove all of the whitespaces between "[tagQuote=" and "]...[/tagQuote]"

View Complete Post

More Related Resource Links

Regex.replace [h2] to


I try to replace [h2] to <h2>
I use this coding:

string o = "<h2>test</h2>";
o = Regex.Replace(o, "[h2]", "<h2>");
o = Regex.Replace(o, "[/h2]", "</h2>");


But the result after the first regex is:


So that is not what i want.
After the first 1, he should make:


Whats wrong?

Split string using Regex with escape sequences

What is the regex to split a string using the delimiter ';', but not split on '\;' ? Backslash would be my escape character in my split string, so finding '\;' would not split, but '\\;' would split. For example I want a regex that would split the following:     "aaa;bb;cccc\;dd\;eee\\;ff\\;ggg\\\;hhh" into the following string array:     aaa     bb     ccc\;dd\;eee\\     ff\\     ggg\\\;hhh   Thanks!   -Sylvain

get the string of 6 numbers following a dash and a space

I need to retrieve a string of 6 numbers which following a dash and space e.g - "John Smiley - 023112 - California" I would like to get the "023112" part

RegEx Request - Extract an tag from string...

Hello, Can anyone give me a regular expression that will extract the <img> tag from a string.  I am receiving descriptions from an rss feed and the description contains an <img> tag in the text.  I want to extract the <img> so that I can display it in a different location on my page. I have fooled with some regular expressions, but my knowledge of them is not very good. Thanks in advance for any help!!

String.Replace With wildcard (and use whatever "wildcard" is)

Hello there,I'm hoping someone out there know a way to accomplish what I'm trying to do, because I'm currently stuck :) What I want to do is to replace lets say ##test## with Something(test)..I know that I can find ##test## by: (Though don't know whether there's a smarter way)System.Text.RegularExpressions.Regex.Replace(str, "##Test.*##", "Output")So basically the problem is to get what the wildcard (.*) is, since thats really what I need to know..Anyone with a brilliant idea how to accomplish this?

Regular expression: Replace anything that isn't alphanumeric with a space?

Hi there,I'm writing a function in C# that will clean up a filename that a user might upload.One of the requirements is to replace any character that isn't alphanumeric with a space, but I can't seem to get the regular expression working to do so?I've include my code below, thanks for any help :)// Replace miscellaneous characters with a space inputFilenameRegex = new Regex(@"^[a-zA-Z0-9]"); inputFilename = inputFilenameRegex.Replace(inputFilename, " ");

Replace string in xml without converting to varchar using SQL Server

We have a xml datatype in SQL server which gets a xml file loaded into it. We want to replace some of the content in the xml datatype, but are running into problems converting from xml to varchar(for manipulation purposes), back to xml to output. Does anyone know of a way to replace xml without converting to varchar?Thanks in advance

replace empty string with value if it is empty in ssrs

I need to place a "Days Not Calculated" of the string is empty, if it is not empty then a need to use the days calculated and put "days old" on the end of the number....SSRS 2K5 iif (Fields!AGE.Value, "", "Days Not Calculated")& " Days Old "

what does the @ in string.Replace(@"\'","") do?

hi,can anybody please explain me what does the @ character in the function above do?thanks guys

Extract String using RegEx

HelloI have below data in string format in a field in table and would like to parse the name from the quantity. The name should be anything before it hits a numeric numberin below example CHLORPHENIRAMINE is the name. i really appreciate if i can get a regex to extract the name from below string                                    "CHLORPHENIRAMINE 8MG CAP SA",                                    "CHLORPHENIRAMINE 12MG CP SA",                                     "CHLORPHENIRAMINE 4MG TABLET",                                     "CLEMASTINE FUM 2.68MG TAB",             &n

A Href removing space when passing a string in a email

In an email action I'm building a string using an <A href.  I'm working with a list called Document Sets and also a column called Document Set.  I'm passing to a page the current document set in order to filter a web part. 

Here is the example

<A href="http://test.net/sites/r3bs/DocSetPAHO/Site%20Pages/dynamic.aspx?DocumentSet=<%Document Set%>">Click here to review the items.</A>

The problem is that when the document set column data contains a space (such as Company Overview), the email removes the space between Company and Overview (as seen below).  If I add the Document Set column to the email directly it displays fine with the space 

[%Document Sets:Document Set%]


I've tried storing the value to a workflow variable but it still removes the space in the actual email.

Replace the string after comma starts in MS SQL


Hi All

Could you anybody help me, How to replace the remaining String after the Comma Starts Using SQL Query.  Below is the data

"MediaRights, MediaRightsLink, MediaRightsCompanies, MediaRightsTypes"

EvtBids 1
MediaRights, MediaRightsLink, MediaRightsCompanies, MediaRightsTypes 1
MediaRightsLink 8
SponsorRights, SponsorRightsLink, SponsorRightsBrands, SponsorRightsTypes 3
SponsorRights, SponsorRightsLink, SponsorRightsCompany, SponsorRightsCompanyTypes 1

regex replace - but with a few exceptions.


I have a string containing HTML and I need to replace some words to be links (I know, working with regex against HTML is not accepted by all developers, but I cannot see an easy solution with any other technique) - I do this with the following code;

string lNewHTML = Regex.Replace(lOldHTML, "(\bword1\b|\bword2|word3\b)", "<a href=\"page.aspx#$1\">$1</a>", RegexOptions.IgnoreCase);

The code works, but I need to include some exceptions to the replace - e.g. I will not replace anything i an img-, li- and a-tag (including link-text and attributes like href and title) but still allow replacements in p-, td- and div-tags.

By using the following code I can avoid replacing in attributes;


But with the above code it still replaces words in e.g. links and headlines which is a no-go.

The last example I have seems to do what I need - but if my HTML-string contains more than a few characters my application crashes;


Can anyone figure out a solution to this?

I need to replace a big string with more than one value



i need to replace a string like change the dataformat, Uppercase,lowercase e.t.c


Ex: I started this question on Sep/29/2010 till i didn't get any REplay.


This has to be change to ...

I Given this question on 29/9/2010 Still i don't got any replay.



How to solve like this type of issue.

Note : this is not my exact requirement, but it matches similar. My String can consists of minimum 500000 words.


Need Regex.Replace help for lowercase to uppercase



I need help with Regex replacement.  I searched the web and tried for several hours but I just can't get it working. 

In theory, what I need to do is simple: make sure all element names in HTML tags are uppercase, e.g.:




If anyone could help me out I would greatly appreciate it!  


How to check for space in a password regex having multiple condition

I have a requirment where in the password field should accept all keys except space, it should have atleast one number , length should be 6 to 50
I tried following but did not work
1) Regex = @"^.*(?=.{6,50})(?=.*\d)(?=.*[a-zA-Z]).*$"

2) ^(?=[^\s])(?=[^\s]{6,50})(?=[^\s]*\d)(?=[^\s]*[a-zA-Z]).*$

Following are my test input text ( test case no 2 is having space at end)

ShouldNOT 654321-4
Should NOT654321-5
S houldNOT654321-6
ShouldNOT65432 1-7
S houldNOT 654321-9

Please help.

Thanks in Advance.
Rajendra Dewani

Regards Rajendra Dewani

Regex solution to ID Excel Cell references in an Excel Formula string


Is there a RegEex solution to accomplish the following:

- Assuming Operator Pattern is "[/*^&()=<>,+-]"
- Cell References are pre-fixed Post-fixed by an Operator (including a comma)
- Cell References Start with Alpha Characters without-interruption - by an operator
    then Followed by numerics-without-interruption - by an operator

----------------------FORMULA STRING INPUT----------------| |---OUTPUT---|
                                                                                        Cell    Cell
1) =I82*I83/365*0.11      <  <  <  <  <  <  <  <  <  <  <  < >  I82     I83
2) =IF(H84>H80*0.91,H84,0.91*H80) <  <  <  <  <  <  <  < >&nbs

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend