Archive

Posts Tagged ‘regex’

RegEx to Replace multiple line breaks in Asp.net

October 4, 2010 Leave a comment

Suppose the text is

“Long Description

With

Multiple

Line

Breaks”

Mulitple line breaks can be replaced with regex as follows:

Regex.Replace(yourlongtext, "[\r\n]+", " - - ");
Advertisements

Replace white spaces – blank spaces in string using Javascript

September 27, 2010 Leave a comment

Regex make our life simpler, and when used properly can create miracles. One such example  Regex is given below which replaces white spaces/blank spaces in string using javascript :

function ReplaceWhiteSpaces()
{
 var text = "Example to Replace white spaces in strings";
 text = text.replace(/\s/g, "-");
 alert(text);
}

Output : Example-to-Replace-white-spaces-in-strings

Regex Used : /\s/g