M
M
Maxim2020-04-20 16:55:05
PHP
Maxim, 2020-04-20 16:55:05

How to properly parse a string?

Good afternoon!
I have variables containing strings, some of which contain an element consisting of 2-3 numbers and one letter.
For example:

$a = 'Service code 145a is used for...';
$b = '...you are to use code 99a.';

I need to somehow parse the values ​​of a variable that may contain similar code. The number and the digits themselves are unknown, but it is known that there is always an "a" after 2-3 digits. The position of this code in the line can change.
How can I make a template, for example for preg_match, that allows you to find such codes in strings?
Ultimately, I need to leave only the code.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rsa97, 2020-04-20
@ikfah012

/(\d+)a/

H
hesy, 2020-04-20
@hesy

https://regex101.com/r/5A4mDU/1/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question