for example I have this string. #345-6574#56-2432#776-246554#
I want to take all values between sharps.
I tried this but not working
preg_match_all('/^#[\d]+-[\d]+#$/',$string,$output);
explode() should be faster. It also is also easier to understand which makes future maintenance easier.This will do:
preg_match_all('/#(\d+\-\d+)#/',$string,$output);
You use lookahead and lookbehind as well if you want to make sure # to be at the both ends.
preg_match_all('/(?<=#)(\d+\-\d+)(?=#)/',$string,$output);