Quantcast
Channel: How to ignore whitespace in a regular expression subject string? - Stack Overflow
Browsing latest articles
Browse All 8 View Live

Answer by cheve for How to ignore whitespace in a regular expression subject...

The accepted answer will not work if and when you are passing a dynamic value (such as "current value" in an array loop) as the regex test value. You would not be able to input the optional white...

View Article



Answer by Konrad Höffner for How to ignore whitespace in a regular expression...

While the accepted answer is technically correct, a more practical approach, if possible, is to just strip whitespace out of both the regular expression and the search string.If you want to search for...

View Article

Answer by Bob for How to ignore whitespace in a regular expression subject...

This approach can be used to automate this(the following exemplary solution is in python, although obviously it can be ported to any language):you can strip the whitespace beforehand AND save the...

View Article

Answer by Aurimas for How to ignore whitespace in a regular expression...

Addressing Steven's comment to Sam Dufel's answerThanks, sounds like that's the way to go. But I just realized that I only want the optional whitespace characters if they follow a newline. So for...

View Article

Answer by Tim Pietzcker for How to ignore whitespace in a regular expression...

If you only want to allow spaces, then\bc *a *t *s\bshould do it. To also allow tabs, use\bc[ \t]*a[ \t]*t[ \t]*s\bRemove the \b anchors if you also want to find cats within words like bobcats or catsup.

View Article


Answer by Kludge for How to ignore whitespace in a regular expression subject...

You could put \s* inbetween every character in your search string so if you were looking for cat you would use c\s*a\s*t\s*s\s*sIt's long but you could build the string dynamically of course.You can...

View Article

Answer by Sam Dufel for How to ignore whitespace in a regular expression...

You can stick optional whitespace characters \s* in between every other character in your regex. Although granted, it will get a bit lengthy./cats/ ->/c\s*a\s*t\s*s/

View Article

How to ignore whitespace in a regular expression subject string?

Is there a simple way to ignore the white space in a target string when searching for matches using a regular expression pattern? For example, if my search is for "cats", I would want "c ats" or "ca...

View Article

Browsing latest articles
Browse All 8 View Live




Latest Images