Skip to content

Instantly share code, notes, and snippets.

@lord-alfred
Last active March 19, 2019 16:00
Show Gist options
  • Save lord-alfred/7638d75d0cb2e2b05e714e2e90a7d3c7 to your computer and use it in GitHub Desktop.
Save lord-alfred/7638d75d0cb2e2b05e714e2e90a7d3c7 to your computer and use it in GitHub Desktop.
Regular Expression For Special Characters & PHP Script For Get Special Characters Ranges
[\x21-\x2F\x3A-\x40\x5B-\x60\x7B-\x7E]
<?php
$ranges = [
['21', '2F'],
['3A', '40'],
['5B', '60'],
['7B', '7E'],
];
$regexp_symbols = [];
foreach($ranges as $range) {
$start = $range[0];
$end = $range[1];
$symbols_map = '\x' . $start . '-\x' . $end;
echo $symbols_map . ': ';
$start = hexdec($start);
$end = hexdec($end);
for ($i = $start; $i <= $end; $i++) {
echo hex2bin(dechex($i));
}
echo PHP_EOL;
$regexp_symbols[] = $symbols_map;
}
echo PHP_EOL . 'Regexp For Special Characters: [' . implode('', $regexp_symbols) . ']' . PHP_EOL;
@lord-alfred
Copy link
Author

lord-alfred commented Mar 19, 2019

➜  tests git:(master) ✗ php script.php
\x21-\x2F: !"#$%&'()*+,-./
\x3A-\x40: :;<=>?@
\x5B-\x60: [\]^_`
\x7B-\x7E: {|}~

Regexp For Special Characters: [\x21-\x2F\x3A-\x40\x5B-\x60\x7B-\x7E]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment