How can I use regular expressions to match consecutive numbers? Regular number
① $ Number = 1234784;
The result of regular expression matching is: 1234.
② $ Number = 389456723;
The result of regular expression matching is: 4567.
Reply to discussion (solution)
Continuous numbers cannot be matched only by regular expressions.
Continuous numbers cannot be matched only by regular expressions.
What should I do?
Is the first 78 not continuous? Is the second 89 and 23 not continuous? Why not?
Is "386387" continuous? Do you want to match?
① $ Number = 1234784;
The result of regular expression matching is: 1234.
② $ Number = 389456723;
The result of regular expression matching is: 4567.
Does it seem to match four consecutive digits? If yes, there are several situations:
$ S = 389456723;
// Four consecutive digits
$ R = '(1234 | 2345 | 3456 | 4567 | 5678 | 6789 )';
Preg_match_all ('/'. $ r. '/', $ s, $ m );
Print_r ($ m [0]);
// More than three consecutive digits
$ R = '(1234 | 2345 | 3456 | 4567 | 5678 | 6789 | 123 | 234 | 345 | 456 | 567 | 678 | 789 )';
Preg_match_all ('/'. $ r. '/', $ s, $ m );
Print_r ($ m [0]);
// If there are more than two characters, you don't need to demonstrate it.
Does it seem to match four consecutive digits? If yes, there are several situations:
$ S = 389456723;
// Four consecutive digits
$ R = '(1234 | 2345 | 3456 | 4567 | 5678 | 6789 )';
Preg_match_all ('/'. $ r. '/', $ s, $ m );
Print_r ($ m [0]);
// More than three consecutive digits
$ R = '(1234 | 2345 | 3456 | 4567 | 5678 | 6789 | 123 | 234 | 345 | 456 | 567 | 678 | 789 )';
Preg_match_all ('/'. $ r. '/', $ s, $ m );
Print_r ($ m [0]);
// If there are more than two characters, you don't need to demonstrate it! Good!