'/-[0-9]+x[0-9]+\./i'
is a string.
/-[0-9]+x[0-9]+\./i
is regex.
Example 1:
"hi".match('/hi/') // returns null
"hi".match(/hi/) // returns ["hi"]
Example 2:
"Hello Onbiponi, on. Hello".replace(/Hello (.*), (.*)\. Hello/, "$1 $2") //$1=Onbiponi and $2=on
You may use(i.e. /gi at the end) if you need to replace more than one match, but that's it.Q. Write in a function to show only Bangla, English letters and number. Replace other characters with a hyphen(-).Answer:JavaScript:function sanitize(s) {
s = s.toLowerCase();
s = s.replace(/[^\u0980-\u09FF\u0041-\u005A\u0061-\u007A\u0030-\u0039 ]/ug, ' ');
s = s.trim();
return s.replace(/\s+/g, '-');
}
PHP:function sanitize($slug) {
$slug = \strtolower($slug);
$slug = preg_replace('/[^\x{0980}-\x{09FF}\x{0041}-x{005A}\x{0061}-\x{007A}\x{0030}-\x{0039} ]/u', ' ', $slug);
$slug = trim($slug);
return preg_replace('/\s+/', '-', $slug);
}
Labels: JavaScript, PHP, Web development