Q: How to remove 4digitnumber/2digitnumber with preg_replace? How to remove 4digitnumber/2digitnumber with preg_replace ?
I try this code :
<?
$data1 = 2018/01;
$data2 = preg_replace('%\/\d{4}\/\d{2}\/%', '', $data1);
echo $data2;
?>


A: There are many regex you can perform here. The easiest one is to clear all but the / like this:
<?php
    $data1 = '2018/01';
    $data2 = preg_replace('/[^\/]+/', '', $data1);

    echo $data2;
    // prints '/'
?>


If you always have 4 digits before the / and two digits after you could also make a regex list:
<?php
    $data1 = '2018/01';
    $regexList = array('/^[\d]{4}/', '/[\d]{2}$/');

    $data2 = preg_replace($regexList, '', $data1);

    echo $data2;
    // prints  '/'
?>

here the whole regex list will be exected. The first list element is the regex for the first half of the string and the second for the second half.
The ^ matches the beginning of the string (except when it's inside [ ] then it's a char negation) while the $ matches the end.

If you wanted to delete any amount of digits before and after the / you would do this:
<?php
    $data1 = '206789678918/0179679';
    $regexList = array('/^[\d]*/', '/[\d]*$/');

    $data2 = preg_replace($regexList, '', $data1);

    echo $data2;
    // prints  '/'
?>

The * identifier matches 0 or more of the elements. If you wanted at least one number to be present before or after the / then you would use + which matches at least one of the elements.

A: i've edited your code. the problem was your regular expression was looking for 
/1234/12/
instead of 1234/12
(where 1234 can be any 4 digit number, and 12 can be any 2 digit number).
and your $data1 variable should be a string
$data1 = '1232018/01abc';
$data2 = preg_replace('/\d{4}\/\d{2}/', '', $data1);
echo $data2;

