Regex in your PHP code

28 March 2020 (Saturday) 10:13pm

Regex is the common word as Regular Expression is commonly used to find a pattern of string. It also can verify the value of the data is valid or invalid. This technic is widely used in search and match any string with the specific pattern. Python and Perl were the main programming language since 1980s. Now there will have many Programming Language will provide regex capability either self-build, build-in or via Programming Libraries. Below is the regex code :-



In PHP you can used preg_match() library to do the REGEX matching as sample PHP code as shown below :-

if (preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $varRegex)) { return “Match IP Address Pattern”; }

Below is the simple PHP code for you to extract data and return in JSON format. It will take time for me to insert more pattern to soeed up your coding time. Do drop comment if you want to add your pattern into my API code.

<?php
$cURLConnection = curl_init();
$varData = '820720888888' // Your Value;
curl_setopt($cURLConnection, CURLOPT_URL, 'https://www.vinclab.com/v2/regexchecker/' . $varData);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($cURLConnection,
CURLOPT_RETURNTRANSFER, true);
$jsonData = curl_exec($cURLConnection);
curl_close($cURLConnection);
$jsonArrayResponse = json_decode($jsonData);
?>


the JSON Output will be listed below :-
{"data":"820720888888","match":"Malaysia Identity Number","regex":"\/^\\d{6}-\\d{2}-\\d{4}$\/"}


Flowers