preg-match

PHP preg match *.domain.com or *.domain.co.uk

孤者浪人 提交于 2021-01-28 08:45:58
问题 I'm using this code to preg match for *.domain.com but need it changed to also include foreign domains which have a few periods like *.domain.co.uk. Any helps appreciated thanks if (trim(preg_match('!^https?://([^/]+\.)?domain\.com(/|#|$)!i', $documentLink->getAttribute('href')))) Just an update that i'm looking to match *.domain.(any TLD) not just co.uk Thanks 回答1: !^https?://([^/]+\.)?domain(.com|co.uk)(/|#|$)!i 回答2: !^https?://([^/]+\.)?domain[.a-z]+(/|#|$)!i 回答3: !^(https?://)?([\w-]+\.)

Regex to find not start and end with dot and allow some special character only not all

你。 提交于 2021-01-13 10:02:18
问题 I am trying to match a string which is not start and and with (.)dot and allow some special char like underscore(_) in string i found dot match regex but not able to match special character what i have done preg_match('/^(?![.])(?!.*[.]$).*$/', $str) Not allowed .example example. example?ghh. (or some more special char not allowed in string) allowed exam.pl56e exmple_ _example_ exam_ple So string will be 1. Not start with dot but in the middle can be a dot(.) 2. String Not allow special char

Regex to find not start and end with dot and allow some special character only not all

狂风中的少年 提交于 2021-01-13 10:00:47
问题 I am trying to match a string which is not start and and with (.)dot and allow some special char like underscore(_) in string i found dot match regex but not able to match special character what i have done preg_match('/^(?![.])(?!.*[.]$).*$/', $str) Not allowed .example example. example?ghh. (or some more special char not allowed in string) allowed exam.pl56e exmple_ _example_ exam_ple So string will be 1. Not start with dot but in the middle can be a dot(.) 2. String Not allow special char

Regex to find not start and end with dot and allow some special character only not all

走远了吗. 提交于 2021-01-13 09:59:28
问题 I am trying to match a string which is not start and and with (.)dot and allow some special char like underscore(_) in string i found dot match regex but not able to match special character what i have done preg_match('/^(?![.])(?!.*[.]$).*$/', $str) Not allowed .example example. example?ghh. (or some more special char not allowed in string) allowed exam.pl56e exmple_ _example_ exam_ple So string will be 1. Not start with dot but in the middle can be a dot(.) 2. String Not allow special char

PHP split string on word before colon

[亡魂溺海] 提交于 2020-07-31 06:01:25
问题 I have a string that looks like this: aaaaa: lorem ipsum bb: dolor sit amet ccc: no pro movet What would be the best way to split the string into an array and get the following result in PHP? array[0]='aaaaa: lorem ipsum'; array[1]='bb: dolor sit amet'; array[2]='ccc: no pro movet'; I can write a function that finds the position of each ":", finds the length of the word before it, and splits the string. But I guess there is an easier way using regular expressions? 回答1: For this kind of job, I

Php check if string contains multiple words

安稳与你 提交于 2020-05-27 08:33:13
问题 I have looked around the internet for something that will do this but it will only work with one word. I am trying to build a script that will detect a bad username for my site, the bad username will be detected if the username contains any of the words in an array. Here's the code I made, but failed to work. $bad_words = array("yo","hi"); $sentence = "yo"; if (strpos($bad_words,$sentence)==false) { echo "success"; } If anybody could help me, I would appreciate it. 回答1: use substr_count for

regex101.com VS myserver - different results

微笑、不失礼 提交于 2020-04-30 07:30:29
问题 I get differents results, anyone could tell me why? RegExp: [0-9]+(?:\s){0,10}(?:\r?\n?)([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2}),([0-9]{1,3}) --> ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2}),([0-9]{1,3})(?:\s){0,10}(?:\r\n|\n|\r){1}(.*\r?\n?.*\r?\n?.*)(?:\n|\r)(?:\n|\r) On Regex101 I use 'gm' modifiers. On PHP I use: preg_match_all($this->Pattern, $txt, $matches, PREG_SET_ORDER); Regex101 result (look match 4 - this is correct. Pattern get only empty line, without any "time line text"): MATCH 1 1. [2

preg_match(): Compilation failed: invalid range in character class at offset

耗尽温柔 提交于 2020-04-28 21:39:53
问题 Thank you in advance for you time in helping with this issue.. preg_match(): Compilation failed: invalid range in character class at offset 20 session.php on line 278 This stopped working all of a sudden after months of working, after a PHP upgrade on our server. Here is the code else{ /* Spruce up username, check length */ $subuser = stripslashes($subuser); if(strlen($subuser) < $config['min_user_chars']){ $form->setError($field, "* Username below ".$config['min_user_chars']."characters"); }