Page 1 of 1

Replacing the last space

Posted: Wed Sep 19, 2007 3:13 am
by theozaf
Hello guys I am really new to your forum, I have searched through the pages to find a solution before posting but didn't find anything matching my question.....

Well I have a string which always ands by ; I mean string ; and in that point I want to replace the space between the string and ; character. what is the correct expression to say replaceAll("\\s+\\;", "") I have tried this and it doesn't work....

thank you

Posted: Wed Sep 19, 2007 3:26 am
by theozaf
OK I found the solution my own just for anyone who needs in the future

"\\s+\\;", ";" otherwise it replaces the space and the ; together

Posted: Wed Sep 19, 2007 4:55 am
by GeertDD

Code: Select all

preg_replace('/\s++(?=;)/', '', $str);

Another solution

Posted: Sat Oct 20, 2007 3:59 am
by regexpert

Code: Select all

preg_replace("/(.*?)\s+(;)\s+/","$1$2",$string);