I want to make regular expression to the following string :
2004 aston….martin db9 31 m3.img
I want the pattern to match all the spaces and dots except the last dot (for the extension )
i did the following pattern
/\s{1,}|\.{1,}/
this pattern match all dots and spaces including the last dot how can i exclude the last dot from the string
Ok here is the code also ( PHP )
$file = "2004 aston....martin db9 31 m3.img";
echo preg_replace("/\s{1,}|\.{1,}/", "_", $file);
and the output is
2004_aston_martin_db9_31_m3_img
Your regex is equivalent to
/\s+|\.+/If you can use lookaheads, then you can do something like that: