preg-match

Validate UK short postcode

筅森魡賤 提交于 2020-01-30 13:16:08
问题 I'm using this validator: //validate postcode function IsPostcode($postcode) { $postcode = strtoupper(str_replace(' ','',$postcode)); if(preg_match("/^[A-Z]{1,2}[0-9]{2,3}[A-Z]{2}$/",$postcode) || preg_match("/^[A-Z]{1,2}[0-9]{1}[A-Z]{1}[0-9]{1}[A-Z]{2}$/",$postcode) || preg_match("/^GIR0[A-Z]{2}$/",$postcode)) { return true; } else { return false; } } From this link. But I want to be able to validate postcodes like ME20 and TN10 instead of a full blown ME20 4RN, TN0 4RN. Can someone help me

Validate UK short postcode

谁说我不能喝 提交于 2020-01-30 13:15:09
问题 I'm using this validator: //validate postcode function IsPostcode($postcode) { $postcode = strtoupper(str_replace(' ','',$postcode)); if(preg_match("/^[A-Z]{1,2}[0-9]{2,3}[A-Z]{2}$/",$postcode) || preg_match("/^[A-Z]{1,2}[0-9]{1}[A-Z]{1}[0-9]{1}[A-Z]{2}$/",$postcode) || preg_match("/^GIR0[A-Z]{2}$/",$postcode)) { return true; } else { return false; } } From this link. But I want to be able to validate postcodes like ME20 and TN10 instead of a full blown ME20 4RN, TN0 4RN. Can someone help me

regex preg_match for digit in middle for a string

孤人 提交于 2020-01-30 13:05:44
问题 ddw_0_op1 ddw_1_op1 ddw_2_op1 ddw_3_op1 ddw_4_op1 in these strings of array how i can extract or preg_match only the number in middle that increase . thanks in advance 回答1: I would break the string on underscore: $parts = explode('_', $string); $middle = $parts[1]; 回答2: If the number never exceeds a single digit, you could simply use $str[4] to get the fifth character of the string (your digit). On the other hand, however, if the numbers continue indefinitely, you could use either of the

regex preg_match for digit in middle for a string

无人久伴 提交于 2020-01-30 13:04:35
问题 ddw_0_op1 ddw_1_op1 ddw_2_op1 ddw_3_op1 ddw_4_op1 in these strings of array how i can extract or preg_match only the number in middle that increase . thanks in advance 回答1: I would break the string on underscore: $parts = explode('_', $string); $middle = $parts[1]; 回答2: If the number never exceeds a single digit, you could simply use $str[4] to get the fifth character of the string (your digit). On the other hand, however, if the numbers continue indefinitely, you could use either of the

How to make preg_match to find whole word but not separate hyphen-words?

試著忘記壹切 提交于 2020-01-30 08:31:06
问题 if (preg_match('#\b'.$rawword.'\b#i',$body)) { This code finds whole words, but if they are a hyphen word like "ABLE-BODIED" it will find ABLE and BODIED separately. How can modify the expression to accommodate for the dash? 回答1: You can use lookbehind and lookahead operators. This operators looks in behind and after but not match them. for example use \b(?<!-)xyz(?!-)\b for finding whole words of xyz that doesn't have - before or after. 来源: https://stackoverflow.com/questions/5781451/how-to

How do I preg_match for words in Hebrew

我是研究僧i 提交于 2020-01-24 11:34:05
问题 I need a function that matches full words in hebrew in php. Please help. 回答1: Try this regular expression describing Unicode character properties: /\p{Hebrew}+/u 回答2: Assuming your source data is UTF-8 encoded $input = "ט״סת תעסתינג O״ת סOמע העברעו תעחת"; preg_match_all( "/[\\x{0590}-\\x{05FF}]+/u", $input, $matches ); echo '<pre>'; print_r( $matches ); echo '</pre>'; Yields Array ( [0] => Array ( [0] => ט״סת [1] => תעסתינג [2] => ״ת [3] => ס [4] => מע [5] => העברעו [6] => תעחת ) ) I based

How do I get the title and complete class value?

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-17 03:50:21
问题 I have two queries 1) <div class="a b" title="my title"> How do I get the title and complete class value ? ('a' always be a fixed class but not 'b'. Second class can be anything and also possiblity to have more than two classes.) 2) <h1><a link="dynamic_link" class="fix-class">my content< /a>< /h1> Get all attributes(link,class..) of 'a href' tag which belongs to only 'h1' tag Please help me out because I stuck on this point from last two days and not able to get any solution from google.

Using regular expression subpattern to instead of using regular expression 2 times in php

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-16 19:17:08
问题 I'm interested if its possible to make include subpattern (child pattern) into a another pattern that would allow me to convert those 2 preg_match and preg_match_all into one preg_match/preg_match_all. <?php $data = 'office phones tel1 6665555998 tel2 555666888 tel3 555688855 home phones tel1 555222555 tel2 555222444 tel3 555666888'; preg_match('/phones(.*)home phones/', $data, $matches); // 1st operation preg_match_all('/[0-9]{4,12}/', $matches[1], $matches); // 2nd operation var_dump(

preg_match is matching two characters when it should only match one

我的未来我决定 提交于 2020-01-16 12:45:35
问题 I'm trying to extract the special characters (out of a predefined pattern) from a string, but when that string begins with an inverted question mark, "matches" returns first two characters, including a not special one. Eg.: $string = '¿hola?'; $string2 = mb_convert_encoding($string, 'UTF-8'); $regex = mb_convert_encoding('/[a-zäáàëéèíìöóòúùñç]/', 'UTF-8'); if(preg_match($regex, $string2, $matches, PREG_OFFSET_CAPTURE)) { //--> We pick the special characters into "$resultado1": $resultado1 =

preg_match is matching two characters when it should only match one

非 Y 不嫁゛ 提交于 2020-01-16 12:43:24
问题 I'm trying to extract the special characters (out of a predefined pattern) from a string, but when that string begins with an inverted question mark, "matches" returns first two characters, including a not special one. Eg.: $string = '¿hola?'; $string2 = mb_convert_encoding($string, 'UTF-8'); $regex = mb_convert_encoding('/[a-zäáàëéèíìöóòúùñç]/', 'UTF-8'); if(preg_match($regex, $string2, $matches, PREG_OFFSET_CAPTURE)) { //--> We pick the special characters into "$resultado1": $resultado1 =