PHP - Regular Expression Question Trying To Solve This The Past Several Hours
First the problem is not so much php relate, as i actually doing it in C# however regular expression are same on all of them and i dont know any c# forums as good and active as phpfreaks so I've decided to post it here.
My text is: Code: [Select] <div class="15ma">text-special character - numbers </div><div class="15ma">text-special character - numbers </div><div class="15ma">text-special character - numbers </div><div class="15ma">text-special character - numbers </div><div class="15ma">text-special character - numbers </div> No spaces between the dives or new lines. I thought of using this pattern: Code: [Select] <div class="15ma">(.+)<\/div> However kept looking at it and it just grabs the first <div class="15ma"> and the last </div> since i used (.+) it consider all the other as part of the inside text.. Any help would be highly appreciated. Thanks in advanced. Similar TutorialsHi people,
i need to find 16x150gr in Dried Pomegranate Arils16x150gr but the format can vary from
Mt Ceder Balsamic Vinegar 12x250ml to
Mt Ceder Balsamic Vinegar 2x2ltr to
Dried Kalamata Olives 4x1kg. i guess you got the drift
i tried something like : '/[1-9]+x[1-9]+[a-z]+/' but i am so useless at regex.
Thank you!
Hey I'm pretty new to regular expression, so I might have made a silly mistake. I want to check if there are any symbols/special characters (not letters or numbers) in a string. I have the code below. function validateKeywords($kw) { if (preg_match("/[^A-Za-z0-9]/", $kw)) { echo 'validation of keywords failed<br />'; return false; // String contains symbols (not letters or numbers) - incorrect format! } else { echo 'validation of keywords succeeded<br />'; return true; // Correct format } } // Testing validateKeywords('some random string I wrote for testing purposes'); // should succeed validateKeywords('some random 10 string I wrote for testing purposes 2010'); // should succeed validateKeywords('some random, string, I wrote for 19 testing purposes'); // should fail validateKeywords('some, random, string I wrote, for testing purposes'); // should fail The problem is that all 4 calls return false and print that the validation failed. So, where did I mess up? Thanks! Can anyone help me. I have very little knowledge about programming and coding and php, but I am tutoring myself on these. I want to write a code that will search for a movie in this website search => http://myandyourface.com/DELETE/imdb-poster.php. NOTE: in searching for the movie, the movie name with more than one word can be type in in combination form by using the + sign. For example, the movie "the vow", typing that into the search box will be so => the+vow. As an example, I got the result as show below: {"Title":"The Vow","Year":"2012","Rated":"PG-13","Released":"10 Feb 2012","Genre":"Drama, Romance","Director":"Michael Sucsy","Writer":"Jason Katims, Abby Kohn","Actors":"Rachel McAdams, Channing Tatum, Sam Neill, Jessica Lange","Plot":"A car accident puts Paige (McAdams) in a coma, and when she wakes up with severe memory loss, her husband Leo (Tatum) works to win her heart again.","Poster":"http://ia.media-imdb.com/images/M/MV5BMjE1OTU5MjU0N15BMl5BanBnXkFtZTcwMzI3OTU5Ng@@._V1_SX320.jpg","Runtime":"N/A","Rating":"N/A","Votes":"N/A","ID":"tt1606389","Response":"True"} So, this is what I wanted to do, I wanted to write a php code expression that will search for a specific movie and provide the result as above,and then using the regex and str_replace, and others, I will be able to remove all the above detail information and have ONLY the image link as in above, which is => http://ia.media-imdb.com/images/M/MV5BMjE1OTU5MjU0N15BMl5BanBnXkFtZTcwMzI3OTU5Ng@@._V1_SX320.jpg I will appreciate any help in creating a code for this Thanks! Hello everyone,
example string
<?php $string = ""; $string .= "<textarea id='convert'> 'AA' </textarea>"; $string .= "<textarea id='convert'> 'BB' </textarea>"; $string .= "<textarea id='not_convert'> 'AA' </textarea>"; $string .= "<textarea id='not_convert'> 'DD' </textarea>"; ?>I want to change 'AA' to 'ZZ' which is inside textarea with the id convert only. How is it possible with the help of regular expression? Code: [Select] <pre> <pre class="brush:cpp"> <pre class="brush:javascript"> Those can be cpp,javascript,python ... etc. I need to change/replace these into: Code: [Select] <pre> <pre class="brush:cpp"> <pre class="brush:javascript"> Those can be cpp,javascript,python ... etc. I need a generic regular expression for this? Can anyone provide the generic regular expression for this to replace? Trying=> $abc = str_replace(array($generic-regular-expression),'<pre> or <pre class="brush:cpp"> or <pre class="brush:javascript"> ..... ',$str); Hi; i would like to search for a regular expression to grab all printf occurences including the folowing senarios :
printf("something"); printf("something", variables); printf("something", variables, variables); printf("something);something", variables, variables);To simplify the third and fourth cases, the regex should start from printf(" and go intil it find ); with a white space after it. But i didn't realise how to do it. This trick should work also for the first and second case. Thanks Edited by Dareros, 26 September 2014 - 01:27 PM. This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=315144.0 This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=312614.0 This topic has been moved to mod_rewrite. http://www.phpfreaks.com/forums/index.php?topic=316160.0 This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=310676.0 Hey all, I think I get these two wrong: 'blogs/([a-zA-Z0-9\-_\/])' 'blogs/categories/([a-zA-Z0-9\-_\/])' I want the first to match something like blogs/johnmerlino but not blogs/ or not blogs/johnmerlino/abcdef I want the second to match something like blogs/categories/johnmerlino but not blogs/categories/ or blogs/ or blogs/categories/johnmerlino/abcdef Thanks for response. Hello,
I have a file to display
$file_content = file_get_contents("test.php");This file is encoded.... In this file there is a specific tag call change_me <change_me> "<code> <strong>Example Element</strong> </code>" </change_me>I want to use htmlspecialchars_decode function for <change_me> tag only... <change_me> tag is used two times in file. Thanks Edited by arunpatal, 10 July 2014 - 04:15 PM. This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=306546.0 Hi, I've got a form where the user submits a date as a text field (as 12-12-2012 for example) called closing. The form submits fine without my regular expression validation, but whenever I try to validate it, it returns the error message I wrote for if no results turn up. Ive tried: Code: [Select] <?php if (!preg_match ("[0-9]{2}-[0-9]{2}-[0-9]{4}", $_POST["closing"])) { $_SESSION["report"] = "<b>Error:</b> Date is in the wrong format. It must be dd-mm-yyyy<br />"; $_SESSION["reportcount"] = 0; } ?> and Code: [Select] <?php if (!preg_match ("\d{2}-\d{2}-\d{4}", $_POST["closing"])) { $_SESSION["report"] = "<b>Error:</b> Date is in the wrong format. It must be dd-mm-yyyy<br />"; $_SESSION["reportcount"] = 0; } ?> Any ideas? This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=325429.0 This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=317585.0 Hi, I am not that good with understanding REGEX/REGEXP functions but, Could someone please let me know as how can I search through html code for a particular tag having a definite start and definite end. E.g. HTML Code below, it has definite Start of Code: [Select] <div id="ST and definite End of Code: [Select] house='Anything'></div></div></div> Code: [Select] <div id="ST12345678_st" class="r_right_col"> <div class=""></div> <div id=""><span class=""></span></div> <div class=""></div> <div class=""><span class=""></span></div> <div class=""></div> <div class=""> <div style="" id="" fname=Abhishek lname='madhani' division=8C house='Anything'> </div> </div> </div> So the HTML file which I have, has the this particular tag being repeated atleast more than 50 times in whole code. And I am planning to extract each of them seperately. So if someone could help me with REGEX to search for this particular tags in whole file, would be really helpful. Regards, Abhishek Madhani <?php $user = $_GET['user']; $request_url ="http://www.domain.com/logs.shtml"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $request_url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $result = curl_exec($ch); //THIS NEEDS CHANGED!!!!! $regex='|$user - (.*?) - $user|'; preg_match_all($regex,$result,$parts); $logs=$parts[1]; foreach($logs as $log){ echo "<B>".$log."</B><br>"; } curl_close($ch); ?> The logs file looks like username - log info - log info - log info - username For a URL like http-//www.domain.com/view-logs.php?user=strago I want it to spit out just the lines from the log file that got strago - log info - log info - log info - strago I have a field called full_name and it has John Smith as a value. I want to take John and put it to the first_name field and Smith to the last_name field. How do I do this, knowing that the first and last name are separateed by a space? Here's a query I did that does the same thing when they are separated by a COMMA, but I am not familiar with regular expressions enough to modify it to include space instead :-) $newlastname = $row['full_name']; if (preg_match('/^[^,]+(?=,)/', $row['full_name'], $match)) { $newlastname = $match[0]; } list($newlastname,$newfirstname) = explode(',',$row['full_name']); This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=349184.0 |