Click to See Complete Forum and Search --> : regular expression "challenge"


peterworth
March 2nd, 2005, 06:02 AM
well i find it challenging anyway. is the following difficult to do:

replace a string so that only alpha-numeric characters remain, deleting spaces and all EXCEPT if there is a space in the middle of the string - then keep it. if there are spaces at the end or beginning of the string (before or after all alpha-numeric characters) delete them, and if there is more than one space in the middle of the string then only keep the one nearest th end...

i just want to use 1 or 2 preg_replace calls in PHP to do this.

thanks for any help.

khp
March 2nd, 2005, 02:08 PM
If you show us what you got so far, we can talk about how to make it better.

bigBA
March 3rd, 2005, 02:43 AM
well can you post an example... i have problems to understand what you want/are to do with the spaces within the string...

(as a side note: to delete (leading/trailing) whitespaces you doesn't have to use a regexp. ever heard of ltrim/rtrim? :wave: )