A regex to match that range (with unlimited trailing whitespace) might look like:
/((48[8-9]|49[0-9]|50[0-9]|51[0-7]);\s*)/g
Or the shorter (but not as easily read IMO):
/((48[8-9]|(49|50)[0-9]|51[0-7]);\s*)/g
Regex test link
In PHP (flagged as your language), you would make your match using preg_match_all
rather than using g
as pattern modifier. Fore a replacement, PHP's preg_replace()
automatically operates in global mode up to the number of replacements specified by 3rd parameter (if specified).
So code for regex replacement in PHP might look like:
$string = 'Hello אב World';
$regex = '/((48[8-9]|49[0-9]|50[0-9]|51[0-7]);\s*)/';
$replacement = '<div>$1</div>';
$string_with_divs = preg_replace($regex, $replacement);
Edit: To match one or more consecutive occurrences of this pattern and to put a single div
wrapper around them all, you would just need to modify the pattern as follows:
$regex = '/(((48[8-9]|49[0-9]|50[0-9]|51[0-7]);\s*)+)/';