preg-match

Check If Preg Match False instead of True

久未见 提交于 2019-12-03 03:57:30
I have this code that makes sure the username is only letters and numbers but then way my code is set up I need it to check if the preg_match is false. Right now it says "if secure echo this" I need it's logic to say "if not secure say this". Can someone help me out? if (preg_match('/[A-Z]+[a-z]+[0-9]+/', $username)) { echo 'Secure enough'; } You can negate the condition like this: if (!preg_match('/^[A-Za-z0-9]+$/', $username)) { echo 'Secure enough'; } Also, your regex needs to be [A-Za-z0-9]+ if you mean "alphanumeric" (only letters and numbers) as a whole. The regex in your code would

Logical operator AND with php regular expression

情到浓时终转凉″ 提交于 2019-12-03 03:30:30
I'd like to use a kind of logical operator "AND" in my regular expression. I tried this: (?=exp1)(?=exp2) But in PHP ?= doesn't work and need to write my program in PHP language. Is there another method? The expression has to match if there are present all the conditions and in any order. I don't wanna write every permutation like: (exp1)(exp2)(exp3)|(exp1)(exp3)(exp2)|.... PHP does support lookahead expressions. You're probably not using them correctly, though. Assuming you want to match a string that contains all three of foo , bar and baz , you need the regex ^(?=.*foo)(?=.*bar)(?=.*baz)

Regular expression wont produce error echo, could anyone please help me?

試著忘記壹切 提交于 2019-12-02 23:18:48
问题 Regular expression wont produce error echo when field is incorrect, besides that I get Warning: preg_match() [function.preg-match]: Compilation failed: missing ) at offset 12 on line 58. Could anyone please help me I´m pretty desperate. $array = array( "error1" == "1", "error2" == "2", "error3" == "3", "error4" == "4", "error5" == "5", "error6" == "6", "error7" == "7", "error8" == "8", "error9" == "9", "error10" == "10", "error11" == "11", "error12" == "12", ); //the regular expressions of

Get all video qualities from a block of text using a regex

别说谁变了你拦得住时间么 提交于 2019-12-02 21:54:35
问题 I want to get all video qualitys from string. My string: #EXTM3U #EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=350000 128/prog_index.m3u8?key=49bfee85b05d117a2906368428094e94 #EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=750000 500/prog_index.m3u8?key=49bfee85b05d117a2906368428094e94 #EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=1000000 750/prog_index.m3u8?key=49bfee85b05d117a2906368428094e94 #EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=1250000 1000/prog_index.m3u8?key=49bfee85b05d117a2906368428094e94 #EXT-X

How do I get the last part of an url string?

爱⌒轻易说出口 提交于 2019-12-02 21:36:59
问题 I need extract item id from url's like these (number after last slash) http://codecanyon.net/item/test item/12219820 //^^^^^^^^ http://codecanyon.net/item/another item/75219586 //^^^^^^^^ http://codecanyon.net/item/item contain number v1.2/74419586 //^^^^^^^^ Some items has digits in name. How i can extract just id at end of links with regular expression in php? 回答1: This should work for you: (Just take the last part of the url (string) with basename()) echo basename($url); 来源: https:/

Capture groups match with quantifier Regexp

安稳与你 提交于 2019-12-02 21:17:39
问题 I am newbie in regex world, I need to capture some different types of strings. By the way please suggest more elagant way to capture such strings. n = any positive number(not the same) |n||0||0||0||0| |n||n||0||0||0| |n||n||n||0||0| |n||n||n||n||0| |n||n||n||n||n| I have tried to use such regular expression for capturing first and secodn types of strings ^\|([1-9]+)\|(?:([1-9]+)\|){4}|(?:(0)\|){4}$ Zero should be treated as separate char, I need to capture each number or zero The problem now

PHP Extract numbers from a string

断了今生、忘了曾经 提交于 2019-12-02 19:50:50
问题 I want to extract numbers from a string in PHP like following : if the string = 'make1to6' i would like to extract the numeric character before and after the 'to' substring in the entire string. i.e. 1 and 6 are to be extracted i will be using these returned values for some calculations.' i would like to extract the numeric character before and after the 'to' substring in the entire string. i.e. 1 and 6 are to be extracted The length of the string is not fixed and can be a max of 10

preg_replace within the preg_replace

梦想的初衷 提交于 2019-12-02 18:39:08
问题 Right now I'm having issues replacing strings that already come out from preg_match. Lets say I have bbcode of [b]bla[/b] , I have this part working with replacing [b] with <b> , but lets just say for all testing purposes that they did [b]hi [b]test[/b][/b] , what ends up coming out is " hi [b]test[/b] ", with everything being bolded, but the [b] won't get replaced for some reason. Currently this is my expression: /\[b\](.*)\[\/b\]/ Sorry, I didn't show my code, I'm new to this. // Will

Get two words from URL after a slash in PHP

放肆的年华 提交于 2019-12-02 18:26:07
问题 I need to get two words from an URL. So for example I have the following URL: http://mydomain.com/alrajhi/invoice/108678645541 I need to get with PHP only "alrajhi"and the number "108678645541" nothing else. Can you help me please? Thank you so much!! 回答1: $string = 'http://mydomain.com/alrajhi/invoice/108678645541'; $parse = parse_url($string); $explode = explode('/', $parse['path']); Now you have: echo $explode[1]; // alrajhi echo $explode[3]; // 108678645541 回答2: Check out 'parse_url' (PHP

Unknown modifier in regular expression [duplicate]

痴心易碎 提交于 2019-12-02 17:14:49
问题 This question already has answers here : Warning: preg_replace(): Unknown modifier ']' (3 answers) Closed 5 months ago . Does anyone knows why i receive this error : preg_match() [function.preg-match]: Unknown modifier '(' using this method: function checkFBDateFormat($date) { if(preg_match ("/^([0-9]{2})/([0-9]{2})/([0-9]{4})$/", $date, $parts)){ if(checkdate($parts[2],$parts[1],$parts[3])) return true; else return false; } else { return false; } } 回答1: You did not escape your "/" and you