[Solved] Preg_match on multiline text

The idea is to avoid the issue of new lines by not using the dot ($subject is your string): $pattern = ‘~ Project\hNo\.\h\d++\hDATE\h (?<date>\d{1,2}\/\d{1,2}\/\d{1,2}) \s++No\.\hQUESTION\hANSWER\s++ (?<No>\d++)\s++ # all characters but D or D not followed by “ate Required” (?<desc>(?>[^D]++|D(?!ate\hRequired))+) \D++ (?<date_required>\d{1,2}\/\d{1,2}\/\d{1,2}) ~x’; preg_match_all($pattern, $subject, $matches, PREG_SET_ORDER); print_r($matches); Note that i use possessive quantifiers and atomic … Read more

[Solved] How to get attribute of href on the basis of selected text? [closed]

Try this : put id for anchor tag <a id=”anchor1″ href=”https://stackoverflow.com/questions/25931155/site.com/register.php?mid=username&mode=bn&bid=1″> use below javascript <script> var href = document.getElementById(‘anchor1’).href; //get index of ? var indexStart = href.indexOf(‘?’); var indexLast = href.length; //get href from ? upto total length var params = href.substring(indexStart+1, indexLast); //get tokens with seperator as ‘&’ and iterate it var paramsArray = … Read more

[Solved] How to strip parts of the given url using preg_replace (php) [closed]

For this specific case, you don’t need a regular expression, you can just parse the url $url=”http://dev.time.com/wp-content/uploads/2014/08/sheep-shrek-300×199.jpg?w=360″; $parts = parse_url($url); echo $parts[‘host’] . $parts[‘path’]; Missed that you want to strip the size … $data = preg_replace(‘/(-\d+x\d+)\.jpg/’, ‘.jpg’, $data); 1 solved How to strip parts of the given url using preg_replace (php) [closed]

[Solved] Preg_match for a string key

The regex would be this: /^[A-Z0-9]{5}-[A-Z0-9]{5}-[A-Z0-9]{5}-[A-Z0-9]{5}-[A-Z0-9]{5}$/ Regex explanation: Start regex expression /^ Capital A-Z and Numerical 0-9 [A-Z0-9] 5 long exactly {5} Dash between sets End expression $/ <?php $reg = ‘/^[A-Z0-9]{5}-[A-Z0-9]{5}-[A-Z0-9]{5}-[A-Z0-9]{5}-[A-Z0-9]{5}$/’; $string = ‘YTMG3-N6DKC-DKB77-7M9GH-8HVX7’; preg_match($reg, $string, $matches, PREG_OFFSET_CAPTURE); print_r($matches); ?> 7 solved Preg_match for a string key

[Solved] What does this regular expression maens “/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/” [duplicate]

What this big regex commands mean? Pattern #1 Breakdown: / #start of pattern delimiter (@.*@) #Capture Group #1: match an @ sign, then zero or more (as many as possible) of any non-newline character, then another @ sign | #or (\.\.) #Capture Group #2: match a literal dot, then another literal dot | #or (@\.) … Read more

[Solved] More than one preg_match queries? [closed]

if(preg_match($fullname_pattern,$fullname)) Remove Last “)” And add here (preg_match($password_pattern,$password))) Like this: if(preg_match($fullname_pattern,$fullname) && preg_match($email_pattern,$email) && preg_match($password_pattern,$password) ) { 1 solved More than one preg_match queries? [closed]

[Solved] Regex to split string into array of numbers and characters using PHP

Use this regex :(?<=[()\/*+-])(?=[0-9()])|(?<=[0-9()])(?=[()\/*+-]) It will match every position between a digit or a parenthesis and a operator or a parenthesis.(?<=[()\/*+-])(?=[0-9()]) matches the position with a parenthesis or an operator at the left and a digit or parenthesis at the right(?<=[0-9()])(?=[()\/*+-]) is the same but with left and right reversed. Demo here 5 solved Regex … Read more

[Solved] Finding month preg-match

I make a snippet for you, so you can start from here $str=”December 2012 Name: Jack Brown”; $ptr = “/^(?P<month>:Jan(?:uary)?|Feb(?:ruary)?|Dec(?:ember)?) (?P<year>:19[7-9]\d|2\d{3}) (Name:(?P<name>(.*)))/”; preg_match($ptr, $str, $data); echo ‘For ‘.trim($data[‘name’]).’ – ‘.$data[‘month’].’ ‘.$data[‘year’]; the result will be ‘For Jack Brown – December 2012’ this is a array Array ( [0] => December 2012 Name: Jack Brown [month] … Read more

[Solved] What’s the proper syntax in preg_match for validating a string if it contains a alphanumeric value w/ special characters [closed]

If you want to test if a string contains at least one alphanumeric and at least one non-alphanumeric string, use the following regex: /^(?=.*[a-z0-9])(?=.*[^a-z0-9])/i Breakup: / start of regex ^ match the start of the string (?= if the following is present there: .* anything at all (except newlines), then [a-z0-9] an alphanumeric character ) … Read more