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
Using the PHP Http_Accept_Language Server Variable
Best Practice: Import MySQL File in PHP; Split Queries
Use PHP Composer to Clone Git Repo
Running Composer Returns: "Could Not Open Input File: Composer.Phar"
How to Get Greenwich Mean Time in PHP
Run Cron Job on PHP Script, on Localhost in Windows
How to Get File Url Using Storage Facade in Laravel 5
PHP Errors Not Being Displayed in the Browser [Ubuntu 10.10]
If Singletons Are Bad Then Why Is a Service Container Good
How to Get a PHP Class Constructor to Call Its Parent's Parent's Constructor
What Does Using a Single Pipe '|' in a Function Argument Do
PHP Flush That Works... Even in Nginx
How to Specify Composer Install Path
How to Add a Line Break Within Echo in PHP
Clean Links to PHP-Generated JavaScript and CSS
Cakephp-3.X: How to Change the Data Type of a Selected Alias