In PHP you can check the string for compliance with a particular template?

0 like 0 dislike
4 views
Good afternoon. There is a certain template view 111/22 33 444/55 66. Trying to write a function that will test user input against this pattern and then split this string into individual numbers - 111, 22, 33, 444, 55 and 66, respectively. Found out that you need to use regular expressions. Started to read the documentation on them and realized that the deal will have a very long and hard. He is not mastered, so turn to you, experts of the toaster.

Could you suggest any ready solution which just checks a string against this pattern? Have to be this way - 111/22 33 444/55 66. Nominal is the number of characters, spaces, slashes and so on. At the slightest deviation, the function should generate an error. Where in the template the numbers must be only numbers, no letters. Thanks in advance!
by | 4 views

2 Answers

0 like 0 dislike
You should understand the regexps, it is at times simpler than it seems at first glance
$str = "111/22 33 444/55 66"; if (preg_match("/^(\\d{3})\\/(\\d{2})\\s(\\d{2})\\s(\\d{3})\\/(\\d{2})\\s(\\d{2})$/i", $str, $m)){ echo "matches"; print_r($m); }else{ echo "does not match"; }
by
0 like 0 dislike
Good night.
Try to start with the following expression.
But this option I think will suit You better.
by

Related questions

0 like 0 dislike
4 answers
0 like 0 dislike
3 answers
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
110,608 questions
257,186 answers
0 comments
28,662 users