In a recent project, one of the features that I was working on required that the application make periodic calls to a third-party API in order to retrieve a piece of information to be used later throughout the application.
Getting Unique IDs with a RegEx
The short version is ultimately that we can use preg_match and preg_replace to get the information that we need. How we actually do it depends on the structure of the information that’s returned to us.
From here, we can then setup a regular express to parse any string that’s preceded by that specific variable name:
This will grab the value of the variable. After this, we need to remove all non-alphanumeric characters. This includes anything like semicolons, slashes, and so on. We only need the data that’s composed of letters and numbers:
This particular example may be very, very niche and not something that you’re likely to encounter. But, if so, here’s something of reference. If nothing else, it’s something else that I have to look back and and refer to should I hit a scenario like this again.