Search code examples
phpregexpreg-replacewhitespace

Replace two words that may have one or more of any kind of whitespace between them


I'm a newcomer to regular expressions, and am having a hard time with what appears to be a simple case.

I need to replace "foo bar" with "fubar", where there is any amount and variety of white space between foo and bar.

For what it's worth, I'm using php's eregi_replace() to accomplish this.

Thanks in advance for the help.


Solution

  • ... = preg_replace('/foo\s+bar/', 'fubar', ...);