A
A
aopil2021-08-21 18:21:53
PHP
aopil, 2021-08-21 18:21:53

How to make a regular expression for 2 conditions?

There are lines:
ORZD3ML/R
FVAJ2J/R

You need to remove the first 5 characters, and the ending should always be /R, all that is displayed between them.

In the first example, you need to get ML/R,and in the secondJ/R

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
OxCom, 2021-08-21
@aopil

<?php
$p = '/^(.{5})(.*\/R)$/';
$a = [
    'ORZD3MLD/R',
    'ORZD3ML/R',
    'FVAJ2J/R',
];

$r = \array_map(static fn ($l) => \preg_replace($p, '$2', $l), $a);

var_dump($r);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question