RegExLib.com - The first Regular Expression Library on the Web!

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find Strip Unquoted Whitespace
Expression
(?:\s+)|((?:"(?:.+?)")|(?:'(?:.+?)'))
Description
When removing any whitespace from something like an excel formula, you need to strip the whitespace from around cell references or other non-quoted strings, while leaving quoted (both single and double quotes) in tact. It even works when another different quote, or double quote is embedded in the string. You can execute this with a replacement group $1 to replace the spaces with another character (or empty string to remove the spaces). Does not match if the quoted string spans multiple lines (if \r\n is inside the quoted string)
Matches
REGEX ROCKS
Non-Matches
"SOME QUOTED STRING", "REGEX'S ROCKS", 'REGEX ROCKS'
Author Rating: The rating for this expression. Chadwick Posey
Source
Your Rating
Bad Good

Enter New Comment

Title

Name

Comment

Spammers suck - we apologize. Please enter the text shown below to enable your comment (not case sensitive - try as many times as you need to if the first ones are too hard):

Existing User Comments

Copyright © 2001-2025, RegexAdvice.com | ASP.NET Tutorials