I have spent hours and hours on this (it's part of a much larger application) and just can't get past the test code snippet below. I would really appreciate a second set of eyes on this. For purposes of what I am trying to accomplish I am trying to remove all spaces other than the one that appears between the name of "Joe Smith". The problem is that the regular expression on the right of the equal sign ends up capturing the last space before the first character in the name "Joe Smith". Not what I want. I want ALL spaces removed other than any spaces after the first character of any value assigned to MyName. In other words the reg exp should capture "MyName" and "Joe Smith" into the matches array. No spaces other than any after the first character of "J". Anybody got any ideas? Thanks. Carlos
No need for regex in this case, unless there is more to it that you are not telling: $text = "MyName = Joe Smith\n"; $matches = explode( '=', $text ); $matches = array_map( 'trim', $matches ); PHP:
That's very interesting kbluhm. Do you happen to know off the top of your head if your solution is faster than using a regular expression? By the way I believe that if I add a "?" to the second "\s*" that it also works but your solution is definitely cleaner if it is indeed faster. Carlos