Preg_Match Special Characters

preg_match special characters

[\W]+ will match any non-word character.

but to match only the characters from the question, use this:

  $string="sadw$"
if(preg_match("/[\[^\'£$%^&*()}{@:\'#~?><>,;@\|\\\-=\-_+\-¬\`\]]/", $string)){
//this string contain atleast one of these [^'£$%^&*()}{@:'#~?><>,;@|\-=-_+-¬`] characters
}

Preg_match for all special characters, password checking

This pattern would allow all characters that's not a digit or a-Z.

[^\da-zA-Z]

Regarding the \W it's a negated \w, which is the same as [A-Za-z0-9_]. Thus will \W be all characters that's not an english letter, digit or an underscore.

As I mentioned as a comment this is a great resource for learning regex. And here's a good site to test the regex.

preg_match special character like Turkish and other

You probably need to use the u modifier to tell preg_match to treat strings as UTF-8:

https://www.php.net/manual/en/reference.pcre.pattern.modifiers.php

$request_uri = 'https://www.weburl.com/hashtag/ülke';

if (preg_match('~/(hashtag)/([[\w.-]+)~u', $request_uri, $match)) {
$pageFor = $match[2];
}

echo $pageFor; //ülke

preg_match_all for special characters [?]

I just noticed that after ac there is not / in link but you are adding that in regex so just try to remove it or use the below code its working and tested.

<?php

$input_lines = 'https://my.site.com/u/0/ac?export=download&confirm=45vy&id=qNhdhk1jejhXLexLpY3RiDY2oamis">D';
preg_match_all('/(https:\/\/my\.site\.com\/[u]\/[0]\/(ac)(\?).*\">D)/', $input_lines, $output_array);

var_dump($output_array);

This is output - https://prnt.sc/weq86u

Or if there are chances that after ac/? can occur then you can try using / as optional parameter in regex

<?php

$input_lines = 'https://my.site.com/u/0/ac?export=download&confirm=45vy&id=qNhdhk1jejhXLexLpY3RiDY2oamis">D';
preg_match_all('/(https:\/\/my\.site\.com\/[u]\/[0]\/(ac)\/?(\?).*\">D)/', $input_lines, $output_array);

var_dump($output_array);

It will match both links with or without / https://prnt.sc/weqbae



Related Topics



Leave a reply



Submit