regex - By using PHP preg_match, how to get specific substring from string
I would like to get substring:
from the below string:
Please may somebody help me?
Preg_match from / to _.
.*?to match anything between the slash and underscore lazy to make sure it doesn't match all the way to the last underscore.
Edited to make greedy match anything before the /
Performance of regex:
Since it's such a simple pattern you can also use normal substr with strrpos.
Edited to use strrpos to get the last /
Performnce of substring:
Do like this:
Use explode function in place of preg_match for easily get your expected output. And using preg_match, do like this: