.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

Looking for a RegEx expression to eliminate extra whitespace in a line

Posted By:      Posted Date: April 10, 2011    Points: 0   Category :WPF
I have a db column that allows users to input freeform text for, say, a firm name. I would like to remove extra whitespace between names, such that "The   Irvine Company" would become "The Irvine Company". What is the best way to do this?

View Complete Post

More Related Resource Links

multi-line regex in C#

Hi, I am sure this is really simple, but i can't figure it out. I have a string that looks like this: REV=A1 STATUS=Working I would like to grab 'A1' and 'Working', in a single regex, but i cannot seem to handle the linebreak. I have tried putting something together in Rad's Regular expressions designer and this pattern will match it all: REV=(?<Rev>.{2}) STATUS=(?<Status>.+) but i don't know to write a two-lined regex in C#. I have also tried to include the linebreak, with both \n and \r, but none of them worked. So, how is my pattern suppoed to look for this?Nicolai Søndergaard LM Glasfiber A/S

REGEX does not match when line ends with the characters.. also, how to negate words that contain the

\S*(ai|ie)\S*   seems to match all words with characters ai and ie in them.  However it does not match if the line ends with them, how can fix that?Also, how can I match all words that DO NOT contain those characters.. I've tried ?! and [^ to no avail.Thanks in advance for any help or information!

regular expression: Read a multi line paragraph

I am trying to build a regular expression that will capture a paragraph of any length that starts with "Ordinance Summary:" and ends with "<=>" but doesn't actually include them in the selection.  And I need it to stop at the first instance of <=>. Here is an example of what what I might encounter: "Ordinance Summary: Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas porttitor congue massa. Fusce posuere, magna sed pulvinar ultricies, purus lectus malesuada libero, sit amet commodo magna eros quis urna. Nunc viverra imperdiet enim. Fusce est. Vivamus a tellus. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Proin pharetra nonummy pede. Mauris et orci. Aenean nec lorem.<=> Ordinance Sponsor:Rhuarch<=>"   And here is what I would need it to actually capture: Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas porttitor congue massa. Fusce posuere, magna sed pulvinar ultricies, purus lectus malesuada libero, sit amet commodo magna eros quis urna. Nunc viverra imperdiet enim. Fusce est. Vivamus a tellus. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Proin pharetra nonummy pede. Mauris et orci. Aenean nec lorem.   And here is the expression I tried which didn't work: (?<=Ordinance Titl

Help me modify regex code, only one line.

I have this code Dim parts As New List(Of String)(Regex.Split(RichTextBox2.Text, "~\d")) That splits lines in this format into parts: ~1Hello~2~3Bye~4~5Morning~6 So if I do MsgBox(parts(5)), it will show me "Morning". ------------------------------------------------------------------------ I want to do the exact same thing, but now my my line is arranged like this: Hello, Bye, Morning,   

.Net Regex engine seems to hang for the given expression and input

Provided pattern:


Input Test
public List<String> TestFunction(string input, List<String> CategoryList, object[] obj)

Please provide an earliest answer/remedy for the provided expression. I have tried to find relevant documentation of bugs but have not found any clues. Tested on regex test engines as well. But behavior happens to be same in all the cases.


SSRS 2008 R2 - Line chart labels - visibility based on expression?


I would like to control the visibility of a data label in a line chart using an expression. For example, I have a requirement to show the data label for two compariable data points in a line chart where the horizontal axis is time (Q1, Q2, Q3, etc...) and the data points are determined based on a selected parameter. The basic idea is that a user can select to view Q3 as the end point of reporting and the chart will graph a complete time line (e.g. FY 2001 thru FYXX Q3) but only show the label for Q3 and prior year Q3.

I have tried to build an expression in the visibility property of 'Chart Series Labels' but this does not appear to work.


Does Regular Expression (RegEx) able to extract Sentence from paragraphs



I am new to Regular languages; I have been trying to find out whether Regex is able to extract sentences from any paragraph (text) on PDF format based on particular words (pattern).



Can you please outlines this with example in C#


Thank you in advance  

SSIS Expression to send email with dataset on the Mail Subject line.



I have a task - I need to email total number of products sold on the subject line of the mail task.

I have Execute SQL task process like select count(*) from tablename. Then I need to Mail the result set like "Total products sold September 2010 : 15000" on teh subject line.

I created a variable bit i dont know how to assign it on the subject line of the Send Mail Task.

I would really appreciate if you can guide me.

Thanks for your help.


Compressing and Removing extra whitespace from generated HTML in MVC



In my .net MVC app I´ve added two filters of this page  http://stackoverflow.com/questions/855526/removing-extra-whitespace-from-generated-html-in-mvc/4074953:
- CompressFilter by WOPR
- WebWhitespaceFilterAttribute by alphus

In my Controlers I just added:

    public virtual ActionResult Index ()

But sometimes appears this error and the page is not returned.

    Content Encoding Error
    The page you are trying to view cannot be shown because it uses an invalid or unsupported form of compression.

I think the problem is by using both actions.
Is there a better way to do it?
Myabe joining both actions into one?

I try to join both Actions but with this code I got the same Content Encoding Error in all my pages:

#region OnActionExecuting
    /// <summary>
    /// OnActionExecuting code
    /// </summary>
    /// <param name="filterContext">The filter context</param>
    public override void OnActionExecuting ( ActionExecutingCont

Need Regex to eliminate match on certain condition


Apologies for cryptic Title.

I have a simple list of keywords that is used as the expression in a regex:

(Lowes|Home Depot|Starbucks|Wendy|Target|etc. etc.... a couple hundred terms...)

I am searching through html documents so "Target" is a hit if there are any anchor tags with target="_blank".

I need to match any "target" unless the only match for it is "target="

Make sense? Thanks.

Bob - www.crowcoder.com

Regex, continue reading the next line if required ending isn't found


Hello :)

Started investigating Regexps yesterday, and got stuck on a little selfmade experiment ^^
It would be the following(discarded the irrelevant code):

Let's assume this text file :

My Fruit information (Fruit (name apple) (size 30 30 30) (color green) (age 10)) (Fruit (name banana) (size 10 60 10) (color yellow) (age 5)) (Fruit (name ...) (size ... ... ...) (color ...) (age ...))

Let's say I want to print for the apple :

 Fruit number 1 is a apple:
 -sizes are 30 30 30
 -It has a green colour
 -It is 10 days old
If the apple information was on the same line it could easely be done with this Regexps:
Regex Fruits = new Regex(@"\(Fruit \(name (.*)\) \(size (.*)\) \(color (.*)\) \(age (.*)\)\)");

But in my case it has some information on the next line aswell.
I can't just search for (color ... ) 'cause it could give me the wrong line.

So how can I make it so , that it won't stop reading untill it finds the "))" (or end of file, in case this could give errors ) no matter how many lines it has to read.

Googled it a bit, but couldn't find a cle

avoid application freeze from regex.macthes using user entered expression


To my chargrin, I discovered using time limited thread  for regexMatch will not allow abort and still freeze the application.


However the freezing can be avoided despite bad user greedy expression if we precede the the matches inside the thread with


 if (!myRegex.IsMatch (...))


  // some sort state setting including message protected internal variable to indicate timeout



// then the actual matches statment

here is a sample inner class that can be used to do time limted matches

 private class MkMatchSvr


 private string sInput;

 Regex myRegex;

 protected internal string sOut;

 protected internal bool bOut;

 protected internal MatchCollection myMatch;


File.Regex Expression for editing


i am really a beginner in file.regex so if someone explain me how can i search for this expression.

this.label1.Text = "Version      1.1.1.Beta";

How will i write this in file.regex regular expression ??

i want to search this through file.regex and then set new value here through tfsbuild. so please help me as i am really freaked out and cannot find my way out.

Article commenting by line number


I'm wondering what's the best way to approach an online article system that allows users to comment by clicking on the line they are commenting about? Essentially the same way Adobe Acrobat works with comments where you can click anywhere and the text is saved for that location.

I'm assuming a mix of jQuery would be the crux of the interface. The system would need to save comments so that when another user logs in, they will also see the other comments but they can´t edit them - only add their own.

Any suggestions would be great.

New off line application working with sdf file. Need advice


Hey Folks

I am working on a project currently where I need to get data out of a 3rd party vendor's software that uses a .sdf file I looked this up and its a SQL CE file. I was hoping to just link to with with access but thats apparently not going to happen. I need to link to the database extract data from it to a csv file for later use. I also and most important I need to get the data from it and create a report that can be printed while on a customers site that my or may not have web access so I need for this program to be on and off line. I had my webapplication that I have been working on open and was able to bring up the sdf file under the server exploere however I can't seem to get anything out of it when I try to do grid views or detail views errors out.

Can I use one of Visual Studio projects to create this sort of applicaiton if so what would be the best approach. I would love to get an access odbc driver since office is allready installed on the employee's laptop's



Line Break Problem in XSLT


Hi All,

I want to add line break in the xslt but it not working.

Below is the code for adding the line break.

</P> <P>
&lt;xsl:variable name="Collection7"&gt;</P> <P>&nbsp; &lt;xsl:value-of select="$13932"/&gt;&lt;xsl:text&gt;&amp;#xa;&lt;/xsl:text&gt;</P> <P>&nbsp; &lt;xsl:value-of select="$31042"/&gt;&lt;xsl:text&gt;&amp;#xa;&lt;/xsl:text&gt;</P> <P>&lt;/xsl:variable&gt;</P> <P>&lt;td&gt;&lt;xsl:value-of select="$Collection7"/&gt;&lt;/td&gt; </P> <P>&lt;/code]</P> <P>I have tried the below code as well:</P> <P>&lt;xsl:variable name="newline"&gt;
&lt;/xsl:variable&gt;</P> <P>or</P> <P>&lt;xsl:variable name="break"&gt;&amp;lt;br&amp;gt;&lt;/xsl:variable&gt;</P> <P>or </P> <P>addign &lt;br/&gt;</P> <P>then also it not adding the line break.</P> <P>But If I write code like below then it is adding the line break and it works fine.</P> <P>

crystal report -visual studio 2008 dual axis chart (bar & line)


dear all, 

i use crystal report integrated with  vs.2008, and i want to make chart with dual axis (bar & line).

i have used bar chart and input the data with 2 values..

then in chart options > template, i activated the dual axis..

my question is, how i can change the 2nd value with line chart not bar chart??

i'd tried to find the right settings in "chart options" but still can't find the solution.

for information in "chart options" there are 4 sub menu : template, general,titles,grid..

i read in a tutorial there's more sub menu called "series" in crystal report (stand alone version)..

is it possible doing it in Crystal Report VS. 2008?

please,, i need your advice and solution..

Thanx before..


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