The user will input a string similar to 151+328. I need a function to detect the user inputted an operation between two numbers and return them. How to do it? I know how to do the first part with regexes (i.e. [0-9]+\+[0-9], but I don’t have a clue about the second part.
tldr:
function('10+296', '+', 1)='10'
function('10+296', '+', 2)='296'
function('perpderpherp', 'derp', 2)='herp'
This function uses a regex to make sure the string is in the following format: [0-9]+[0-9] and then explode to split and return a part:
This function uses
explodeto split the string at the delimiter and return any of the parts:If the delimiter doesn’t exist, it’ll just return the original string.