wilbur_wc Posted April 16, 2011 Share Posted April 16, 2011 two part question... PART 1... part one is really simple, but for some reason it's just not happening for me... i need to find and replace all numbers which have a space between them... ex: 9 0 8would become 908 & 6 9 would become 69 what're the proper preg_replace attributes i'd need to achieve this? PART 2... this one is a little tricky... i also have some numbers like 1,000 that are showing up as 1 ,000 or 1, 000... so i need to get rid of the unwanted space, but there's a catch... if the line which contains the number we're potentially replacing also contains the string respective, then i need leave the space intact. the reason being, some number/comma combinations represent two separate values as opposed to a thousand delimiter (this case can be identified by the line containing somewhere the string respective). thanks so much Quote Link to comment https://forums.phpfreaks.com/topic/233922-regex-strip-spaces-between-numbers/ Share on other sites More sharing options...
.josh Posted April 17, 2011 Share Posted April 17, 2011 $string = preg_replace('~(?<=[0-9]) (?=[0-9])~','',$string); $string = preg_replace('~(?!.*respective)(?<=[0-9]|,) (?=[0-9]|,)~i','',$string); Quote Link to comment https://forums.phpfreaks.com/topic/233922-regex-strip-spaces-between-numbers/#findComment-1202456 Share on other sites More sharing options...
wilbur_wc Posted April 17, 2011 Author Share Posted April 17, 2011 awesome... thanks Quote Link to comment https://forums.phpfreaks.com/topic/233922-regex-strip-spaces-between-numbers/#findComment-1202470 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.