PHP - Does This Regex Need The Backslash Before The Dot? ^\s+@\s+\.\s+$
For a very 'loose' email address validator, does the following regex need the backslash before the dot?
^\S+@\S+\.\S+$
(Checks for anything@anything.anything but I'm gonna change that to anything.anything to make it even 'looser')
I tested with and without the backslash using rubular.com and it seems superfluous but I'd like a second opinion or two please.
ALSO: does rubular.com use the right engine to be correct for php? I hope so coz it's the first time I've been able to fully understand some regexes I've been blindly implementing for some time!
Many thanks in advance
Similar TutorialsThe issue I'm having is when the returned data has data to place inside of fields it does but when there isn't data then it shows a backslash and I'm not sure why? Any ideas? Code: [Select] <form action="#" id="bioForm" > <?php while ($row = mysqli_fetch_array($groupsResult, MYSQLI_ASSOC)) { echo "<fieldset> <legend>" . $row['groupName'] . "</legend>"; $fieldsResult = mysqli_query ( $dbc, sprintf($fieldsQuery,$row['ID']) ); echo $fieldsQuery; while ($row2 = mysqli_fetch_array($fieldsResult, MYSQLI_ASSOC)) { echo "<div class=field required>"; if ($row2['inputType'] == "text") { echo "<label for=" . $row2['ID'] . ">" . $row2['fullName'] . "</label>"; echo "<input type=text name=" . $row2['ID'] . " id=" . $row2['ID'] . " class=text biofield title=" . $row2['fullName'] . " value=" . $row2['content'] . " />"; } elseif ($row2['inputType'] == "textarea") { echo "<label for=" . $row2['ID'] . ">" . $row2['fullName'] . "</label>"; echo "<textarea name=" . $row2['ID'] . " id=" . $row2['ID'] . " class=textarea biofield title=" . $row2['fullName'] . " >" . $row2['content'] . "</textarea>"; } else { echo "<label for=" . $row2['ID'] . ">" . $row2['fullName'] . "</label>"; echo "<select name=" . $row2['ID'] . " id=" . $row2['ID'] . " class=dropdown biofield title=" . $row2['fullName'] . " >"; echo "<option value= >None</option>"; if ($styleID == 1 || $styleID == 2 || $styleID == 6) { $charactersQuery = " SELECT characters.ID, characters.characterName FROM characters WHERE characters.styleID = 3 ORDER BY characters.characterName"; } else { $charactersQuery = " SELECT characters.ID, characters.characterName FROM characters WHERE characters.styleID IN (1,2,6) ORDER BY characters.characterName"; } $charactersResult = mysqli_query ( $dbc, $charactersQuery ); // Run The Query while ( $manager_row = mysqli_fetch_array ( $charactersResult, MYSQL_ASSOC ) ) { print "<option value=\"".$manager_row['ID']."\" "; if($manager_row['ID'] == $row2['content']) { print " SELECTED"; } print ">".$manager_row['characterName']."</option>\r"; } echo "</select>"; } echo "</div>"; } echo "</fieldset>"; } ?> <fieldset> <input type="hidden" name="defaultCharID" id="defaultCharID" value="<?php echo $defaultCharID; ?>" /> <input type="submit" class="submit" id="editBio" title="Edit Bio" value="Edit Bio" /> </fieldset> </form> Code: [Select] <?php session_start(); // Access the existing session // Include the database page require ('../../inc/dbconfig.php'); $defaultCharID = $_SESSION['defaultCharID']; $styleIDQuery = " SELECT characters.styleID FROM characters WHERE characters.ID = '" . $defaultCharID . "'"; $styleIDResult = mysqli_query ( $dbc, $styleIDQuery ); // Run The Query $row = mysqli_fetch_array( $styleIDResult, MYSQL_ASSOC ); $styleID = $row[ 'styleID' ]; $groupsQuery = " SELECT groups.* FROM groups WHERE groups.styleID = '" . $styleID . "' ORDER BY groups.ID"; $groupsResult = mysqli_query ( $dbc, $groupsQuery ); // Run The Query $fieldsQuery = " SELECT fields.*, fieldsContent.content FROM fields INNER JOIN fieldsContent ON fields.ID = fieldsContent.fieldID WHERE fields.styleID = '". $styleID . "' AND fields.groupID = '%d' AND fields.statusID = 1 AND fieldsContent.characterID = '". $defaultCharID . "'"; ?> What is the correct way to use the backslash here? I am using an ftp script and retrieving the brand directory name through url. I want to catch it if they try to use \ in the url to list all directories. Code: [Select] elseif($_GET[f]=="\") { echo "You have entered an invalid vendor."; $_SESSION['brand_path'] = "INVALID"; } Is there a way to trim everything off in front of the last backslash in the string? Code: [Select] $trimFile = $fList[$i]; Example: In this path: \\\\myftp/downloads/tom/work/word_docs\\legal\test.pdf I only want to display test.pdf. Thanks, Jake I am working on taking out the Deprecated functions from my site so while replacing ereg with preg_match I get the below error. Per a message I found on the internet it says to replace ereg with preg_match and everything should work. Can anyone assist me with fixing this error? Error: Warning: preg_match() [function.preg-match]: Delimiter must not be alphanumeric or backslash Part where error is contained if (preg_match('enum.(.*).', $row['Type'], $match)) { $opts = explode(',', $match[1]); foreach ($opts as $item) $finalResult[] = substr($item, 1, strlen($item)-2); } Full Function function getEnumOptions($table, $field) { global $db; $finalResult = array(); if (strlen(trim($table)) < 1) return false; $query = "show columns from " . $db['tickets_slave']->escapeSimple($table); $res =& $db['tickets']->query($query); if (PEAR::isError($res)) { throw new TixException($_SERVER['SCRIPT_NAME'] . ":", TixExceptionCodes::UNKNOWN_ERROR); } else { try { while ($res->fetchInto($row)) { if ($field != $row["Field"]) { } else { //check if enum type if (preg_match('enum.(.*).', $row['Type'], $match)) { $opts = explode(',', $match[1]); foreach ($opts as $item) $finalResult[] = substr($item, 1, strlen($item)-2); } } } } catch (TixException $ex) { throw new TixException($_SERVER['SCRIPT_NAME'] . ":", TixExceptionCodes::UNKNOWN_ERROR); } } return $finalResult; } hey guys im after the pattern to replace , and & symbols please?...any help would be great
thank you
I have been playing with reg ex patterns for the last couple of hours. I realized I have been coding in security a hole. But for the life of me I don't know the answer. In preg match it will return a 1 true. So the code below is saying if you find anything that is not one of these values the condition is true. Meaning anything but a-zA-Z true is this correct? How do I make it so if you find anything but a-zA-Z return false? Code: [Select] if ( preg_match('/[a-zA-Z]/', $_GET['contact'] )== 1) I want to make it so if($message=="" . $cmdPrefx . "deleteall: "){ echo substr(strrchr($message, ' '), 1); Doesn't use =="something" How can I make it so anything after deleteall: is a wildcard? I'm assuming using regex, but have no idea how I have a CSV file which has more than 50k records and i want to convert this using regex Well I'm stuck... So I'm trying to make the php print out the text between Code: [Select] title="Text here" <?php function Betweens($string) { $pattern = '/title="(.*?)"/'; //It fails here preg_match($pattern, $string, $matches); return $matches[1]; } $str = '<iu pageid="2022" ns="0" title="Test" />'; $p = Betweens($str); echo $p; ?> So yea I really suck at regex's.. Edit: God damn it, now I see I've posted in wrong sector -.- hello. There is a project i take and i can't handle it. the project goes like this. I get site code by file_get_contents function into variable. Than I need to find the iframe and delete it from the variable. for example the code i getting from the file_get_contents is looking like this : <html> <body> This is site ! <iframe> LINK </iframe> </body> </html> now , simply i can track the iframe and delete it just like this. $str = preg_replace('/\<{1}iframe[a-zA-Z0-9=+\/\'.]/' , '' , $str);/** this is not the right regex i use , the full one contain all chars except < .**/ So I can find the < symbol and than delete all iframe section. the problem come when I get code like this. <html> <body> This is site ! <iframe> <iframe>LINK </iframe></iframe> </body> </html> So , from here I can't handle it since I don't know where the iframe ends since there is many < symbols. Second question is maybe with regex i can handle something like this? looking for start , than get everything between and stop at the end. $reg ='/^\<{1}iframe .+\<{1}iframe\>{1}/i'; Is that possible to do something like this with regex? any suggestions how to make it done? hope i was clear. thanks , Mor. Ok, my first post here (earlier today) was a huge help, so here's a second... I have the following PHP code: $name = $row['NAME']; $nameTrimmed = $name; if ((strlen($nameTrimmed) > 20) && (strlen($nameTrimmed) > 1)) { $whitespaceposition2 = strrpos($nameTrimmed," ",5); $nameTrimmed = substr($nameTrimmed, 0, $whitespaceposition2); echo $nameTrimmed . "..."; } if ((strlen($name) <= 20) && (strlen($name) > 0)) { echo $name; } This is working as expected. However, many of the "name" fields in the DB contain &trade; and &reg; strings, which inflate the count of each product title. Since I'm using the strrpos to limit the length of the longer product names (due to limited space in the layout), I would like to show as many full titles as possible. Many are being cut prematurely short due to the extra characters from the symbols. Do I need to run all this through a regex filter before I count it? If so, can anyone share an example of code I could try? Regex has never been my weak point, let alone my strong point. Or is there something else I haven't thought of? Any help is greatly appreciated! Hey Guys,
I'm receiving an api request back that looks like:
[{"fmrp":8.770560720053982,"fmrr":7.78614635427592e-05,"lrid":174222182518,"lsrc":80972326202,"ltgt":31581262572,"luuu":"groups.google.com/group/comp.infosystems.www.users/msg/9a210e5f72278328","pda":100,"ueid":355370,"uid":358079,"ulc":1394603890,"umrp":7.348021108330069,"umrr":4.2306065019844527e-07,"upa":95.04277845195264,"us":200,"ut":"HTTP cookie - Wikipedia, the free encyclopedia","uu":"en.wikipedia.org/wiki/HTTP_cookie"},{"fmrp":8.770560720053982,"fmrr":7.78614635427592e-05,"lrid":174457993090,"lsrc":80972326202,"ltgt":31622557610,"luuu":"support.google.com/chrome/answer/95582?hl=en","pda":100,"ueid":355370,"uid":358079,"ulc":1394603890,"umrp":7.348021108330069,"umrr":4.2306065019844527e-07,"upa":95.04277845195264,"us":200,"ut":"HTTP cookie - Wikipedia, the free encyclopedia","uu":"en.wikipedia.org/wiki/HTTP_cookie"},{"fmrp":8.770560720053982,"fmrr":7.78614635427592e-05,"lrid":174457997214,"lsrc":80972326202,"ltgt":31622557668,"luuu":"support.google.com/chrome/answer/95626?hl=en","pda":100,"ueid":355370,"uid":358079,"ulc":1394603890,"umrp":7.348021108330069,"umrr":4.2306065019844527e-07,"upa":95.04277845195264,"us":200,"ut":"HTTP cookie - Wikipedia, the free encyclopedia","uu":"en.wikipedia.org/wiki/HTTP_cookie"},{"fmrp":8.770560720053982,"fmrr":7.78614635427592e-05,"lrid":174704422109,"lsrc":80972326202,"ltgt":31675615115,"luuu":"www.google.com/support/chrome/bin/answer.py?hl=en&answer=95582","pda":100,"ueid":355370,"uid":358079,"ulc":1394603890,"umrp":7.348021108330069,"umrr":4.2306065019844527e-07,"upa":95.04277845195264,"us":200,"ut":"HTTP cookie - Wikipedia, the free encyclopedia","uu":"en.wikipedia.org/wiki/HTTP_cookie"},{"fmrp":8.770560720053982,"fmrr":7.78614635427592e-05,"lrid":174704422260,"lsrc":80972326202,"ltgt":31675615123,"luuu":"www.google.com/support/chrome/bin/answer.py?hl=en&answer=95626","pda":100,"ueid":355370,"uid":358079,"ulc":1394603890,"umrp":7.348021108330069,"umrr":4.2306065019844527e-07,"upa":95.04277845195264,"us":200,"ut":"HTTP cookie - Wikipedia, the free encyclopedia","uu":"en.wikipedia.org/wiki/HTTP_cookie"},{"fmrp":8.770560720053982,"fmrr":7.78614635427592e-05,"lrid":174051896270,"lsrc":80975346908,"ltgt":31567049373,"luuu":"books.google.com/?id=0IZboamhb5EC&lpg=PA731","pda":100,"ueid":73314,"uid":156486,"ulc":1393624567,"umrp":6.978036065267593,"umrr":1.3614443568106348e-07,"upa":94.43262161988372,"us":200,"ut":"United States - Wikipedia, the free encyclopedia","uu":"en.wikipedia.org/wiki/United_States"},{"fmrp":8.770560720053982,"fmrr":7.78614635427592e-05,"lrid":174051900386,"lsrc":80975346908,"ltgt":31567051168,"luuu":"books.google.com/?id=58KxPNa0hF4C&lpg=PA463","pda":100,"ueid":73314,"uid":156486,"ulc":1393624567,"umrp":6.978036065267593,"umrr":1.3614443568106348e-07,"upa":94.43262161988372,"us":200,"ut":"United States - Wikipedia, the free encyclopedia","uu":"en.wikipedia.org/wiki/United_States"},{"fmrp":8.770560720053982,"fmrr":7.78614635427592e-05,"lrid":174051902110,"lsrc":80975346908,"ltgt":31567051879,"luuu":"books.google.com/?id=6xiYiybkE8kC&vq=core","pda":100,"ueid":73314,"uid":156486,"ulc":1393624567,"umrp":6.978036065267593,"umrr":1.3614443568106348e-07,"upa":94.43262161988372,"us":200,"ut":"United States - Wikipedia, the free encyclopedia","uu":"en.wikipedia.org/wiki/United_States"},{"fmrp":8.770560720053982,"fmrr":7.78614635427592e-05,"lrid":174051902955,"lsrc":80975346908,"ltgt":31567052243,"luuu":"books.google.com/?id=7veohk0fkLYC&lpg=PA88","pda":100,"ueid":73314,"uid":156486,"ulc":1393624567,"umrp":6.978036065267593,"umrr":1.3614443568106348e-07,"upa":94.43262161988372,"us":200,"ut":"United States - Wikipedia, the free encyclopedia","uu":"en.wikipedia.org/wiki/United_States"},{"fmrp":8.770560720053982,"fmrr":7.78614635427592e-05,"lrid":174051904343,"lsrc":80975346908,"ltgt":31567052883,"luuu":"books.google.com/?id=9iQYSQ9y60MC&lpg=PA49","pda":100,"ueid":73314,"uid":156486,"ulc":1393624567,"umrp":6.978036065267593,"umrr":1.3614443568106348e-07,"upa":94.43262161988372,"us":200,"ut":"United States - Wikipedia, the free encyclopedia","uu":"en.wikipedia.org/wiki/United_States"},{"fmrp":8.770560720053982,"fmrr":7.78614635427592e-05,"lrid":174051905960,"lsrc":80975346908,"ltgt":31567053635,"luuu":"books.google.com/?id=BgZyXNIrvB4C&pg=PT12","pda":100,"ueid":73314,"uid":156486,"ulc":1393624567,"umrp":6.978036065267593,"umrr":1.3614443568106348e-07,"upa":94.43262161988372,"us":200,"ut":"United States - Wikipedia, the free encyclopedia","uu":"en.wikipedia.org/wiki/United_States"},{"fmrp":8.770560720053982,"fmrr":7.78614635427592e-05,"lrid":174051911261,"lsrc":80975346908,"ltgt":31567055934,"luuu":"books.google.com/?id=Ho_RmgOnwgwC&lpg=PA8","pda":100,"ueid":73314,"uid":156486,"ulc":1393624567,"umrp":6.978036065267593,"umrr":1.3614443568106348e-07,"upa":94.43262161988372,"us":200,"ut":"United States - Wikipedia, the free encyclopedia","uu":"en.wikipedia.org/wiki/United_States"},{"fmrp":8.770560720053982,"fmrr":7.78614635427592e-05,"lrid":174051913146,"lsrc":80975346908,"ltgt":31567056717,"luuu":"books.google.com/?id=JttyjBoyb3AC&lpg=PA12","pda":100,"ueid":73314,"uid":156486,"ulc":1393624567,"umrp":6.978036065267593,"umrr":1.3614443568106348e-07,"upa":94.43262161988372,"us":200,"ut":"United States - Wikipedia, the free encyclopedia","uu":"en.wikipedia.org/wiki/United_States"},{"fmrp":8.770560720053982,"fmrr":7.78614635427592e-05,"lrid":174051920509,"lsrc":80975346908,"ltgt":31567059840,"luuu":"books.google.com/?id=SF7U27JsLC4C&dq=iraq+invasion+removes+hussein","pda":100,"ueid":73314,"uid":156486,"ulc":1393624567,"umrp":6.978036065267593,"umrr":1.3614443568106348e-07,"upa":94.43262161988372,"us":200,"ut":"United States - Wikipedia, the free encyclopedia","uu":"en.wikipedia.org/wiki/United_States"},{"fmrp":8.770560720053982,"fmrr":7.78614635427592e-05,"lrid":174051921673,"lsrc":80975346908,"ltgt":31567060362,"luuu":"books.google.com/?id=T_0TrXXiDbUC&dq=slavery+%22American+Civil+War%22","pda":100,"ueid":73314,"uid":156486,"ulc":1393624567,"umrp":6.978036065267593,"umrr":1.3614443568106348e-07,"upa":94.43262161988372,"us":200,"ut":"United States - Wikipedia, the free encyclopedia","uu":"en.wikipedia.org/wiki/United_States"},{"fmrp":8.770560720053982,"fmrr":7.78614635427592e-05,"lrid":174051922547,"lsrc":80975346908,"ltgt":31567060715,"luuu":"books.google.com/?id=UYpVAAAAYAAJ","pda":100,"ueid":73314,"uid":156486,"ulc":1393624567,"umrp":6.978036065267593,"umrr":1.3614443568106348e-07,"upa":94.43262161988372,"us":200,"ut":"United States - Wikipedia, the free encyclopedia","uu":"en.wikipedia.org/wiki/United_States"},{"fmrp":8.770560720053982,"fmrr":7.78614635427592e-05,"lrid":174051925466,"lsrc":80975346908,"ltgt":31567061980,"luuu":"books.google.com/?id=Y1dOLQN9hvwC&dq=SEALs+kill+Osama+bin+Laden","pda":100,"ueid":73314,"uid":156486,"ulc":1393624567,"umrp":6.978036065267593,"umrr":1.3614443568106348e-07,"upa":94.43262161988372,"us":200,"ut":"United States - Wikipedia, the free encyclopedia","uu":"en.wikipedia.org/wiki/United_States"},{"fmrp":8.770560720053982,"fmrr":7.78614635427592e-05,"lrid":174051936195,"lsrc":80975346908,"ltgt":31567066473,"luuu":"books.google.com/?id=jLy-NKnQitIC&pg=PA45&dq=uk+us+special+relationship","pda":100,"ueid":73314,"uid":156486,"ulc":1393624567,"umrp":6.978036065267593,"umrr":1.3614443568106348e-07,"upa":94.43262161988372,"us":200,"ut":"United States - Wikipedia, the free encyclopedia","uu":"en.wikipedia.org/wiki/United_States"},{"fmrp":8.770560720053982,"fmrr":7.78614635427592e-05,"lrid":174051937261,"lsrc":80975346908,"ltgt":31567066890,"luuu":"books.google.com/?id=ka6LxulZaEwC&vq=annexation&dq=territorial+expansion+United+States+%22manifest+destiny%22","pda":100,"ueid":73314,"uid":156486,"ulc":1393624567,"umrp":6.978036065267593,"umrr":1.3614443568106348e-07,"upa":94.43262161988372,"us":200,"ut":"United States - Wikipedia, the free encyclopedia","uu":"en.wikipedia.org/wiki/United_States"},{"fmrp":8.770560720053982,"fmrr":7.78614635427592e-05,"lrid":174051943179,"lsrc":80975346908,"ltgt":31567069364,"luuu":"books.google.com/?id=r71u_AgE7iYC&lpg=PA142","pda":100,"ueid":73314,"uid":156486,"ulc":1393624567,"umrp":6.978036065267593,"umrr":1.3614443568106348e-07,"upa":94.43262161988372,"us":200,"ut":"United States - Wikipedia, the free encyclopedia","uu":"en.wikipedia.org/wiki/United_States"},{"fmrp":8.770560720053982,"fmrr":7.78614635427592e-05,"lrid":174051949934,"lsrc":80975346908,"ltgt":31567072219,"luuu":"books.google.com/?id=yd4GqkP5XYgC&lpg=PA229","pda":100,"ueid":73314,"uid":156486,"ulc":1393624567,"umrp":6.978036065267593,"umrr":1.3614443568106348e-07,"upa":94.43262161988372,"us":200,"ut":"United States - Wikipedia, the free encyclopedia","uu":"en.wikipedia.org/wiki/United_States"},{"fmrp":8.770560720053982,"fmrr":7.78614635427592e-05,"lrid":174051950951,"lsrc":80975346908,"ltgt":31567072673,"luuu":"books.google.com/?id=zq4rsWNrYo4C&q=Reaganomics&dq=Reaganomics","pda":100,"ueid":73314,"uid":156486,"ulc":1393624567,"umrp":6.978036065267593,"umrr":1.3614443568106348e-07,"upa":94.43262161988372,"us":200,"ut":"United States - Wikipedia, the free encyclopedia","uu":"en.wikipedia.org/wiki/United_States"},{"fmrp":8.770560720053982,"fmrr":7.78614635427592e-05,"lrid":174052414947,"lsrc":80975346908,"ltgt":31567405066,"luuu":"books.google.com/books/about/A_History_of_the_American_People.html?id=RXSVQjz1_tMC","pda":100,"ueid":73314,"uid":156486,"ulc":1393624567,"umrp":6.978036065267593,"umrr":1.3614443568106348e-07,"upa":94.43262161988372,"us":200,"ut":"United States - Wikipedia, the free encyclopedia","uu":"en.wikipedia.org/wiki/United_States"},{"fmrp":8.770560720053982,"fmrr":7.78614635427592e-05,"lrid":174052676940,"lsrc":80975346908,"ltgt":31567608329,"luuu":"books.google.com/books/about/An_Empire_of_Wealth.html?id=rmsUs_KDgHAC","pda":100,"ueid":73314,"uid":156486,"ulc":1393624567,"umrp":6.978036065267593,"umrr":1.3614443568106348e-07,"upa":94.43262161988372,"us":200,"ut":"United States - Wikipedia, the free encyclopedia","uu":"en.wikipedia.org/wiki/United_States"},{"fmrp":8.770560720053982,"fmrr":7.78614635427592e-05,"lrid":174054227159,"lsrc":80975346908,"ltgt":31568894639,"luuu":"books.google.com/books/about/History_of_the_American_Economy_With_Acc.html?id=lyhI1q_E4G0C","pda":100,"ueid":73314,"uid":156486,"ulc":1393624567,"umrp":6.978036065267593,"umrr":1.3614443568106348e-07,"upa":94.43262161988372,"us":200,"ut":"United States - Wikipedia, the free encyclopedia","uu":"en.wikipedia.org/wiki/United_States"}]I'm trying to retrieve all the backlinks located in these parts: "uu":"en.wikipedia.org/wiki/HTTP_cookie" "uu":"en.wikipedia.org/wiki/United_States" etc I tried this regex: $regex = returnSeoMozLinks("google.com"); $pattern = '""uu"":""(.*?)""'; $success = preg_match($pattern, $regex, $match); if ($success) { echo "Match: ".$match[0]."<br />"; }But it doesn't seem to work, i can do it in vb net but i am rusty with php lol any help would be appreciated guys! cheers Graham I am trying to use preg_match_all to find some information on a webpage. Here is what I am currently using <?php $homepage = "http://www.example.com"; $page_contents1 = file_get_contents($homepage); $names1 = preg_match_all('/<span class="video_date">(.*)</span> - <a class="b" href="/(.*)/">(.*)</a><br/>\/', $page_contents1, $matches1); echo implode(", ", $matches1[1]); ?> I am trying to match this piece of html: <span class="video_date">Oct 21</span> - <a class="b" href="/meanwhilezealand/"> Meanwhile in New Zealand...</a><br/> Thanks for looking! hey guys im trying to match a certain string with possible matchs like:
:action(activation-key|activation_key2|activation_key3) ...etc
:action(activation-key|activation_key2)
:action(activation-key)
(activation-key) ...etc
unfortunatley im not getting the results im after and am now scratching my head.
here is my code:
$text = ":action(activation-key|activation_key2|activation_key3)"; if (preg_match_all('/<parameter>(.*?)\((.*?)|(.*?)\||\|(.*?)\)$/', $text, $match)) { print_r($match); }my result: Array ( [0] => Array ( [0] => :action(activation-key| [1] => activation_key2| ) [1] => Array ( [0] => [1] => ) [2] => Array ( [0] => [1] => ) [3] => Array ( [0] => :action(activation-key [1] => activation_key2 ) [4] => Array ( [0] => [1] => ) ) a result like this is what im after if anyone could help please: Array ( [0] => Array ( ['parameter'] => :action [0] => activation_key1 [1] => activation_key2 [2] => activation_key3 ) ) thank you guys Edited by Destramic, 25 December 2014 - 06:34 PM. So, I am not very experienced with regexes, so I wanna ask if this code can be simplified with preg_match? It is code from my framework on what I am working for adding routes. To explain what is "default" and "MAP", here is example usage. And, callable is called via call_user_func_array if that helps.
// mapping routes $fw->route('home: GET|POST /', 'home'); // provide ReST interface by mapping HTTP requests to class method $fw->route('MAP /rest', 'some_class'); // default route (404 page) $fw->route('default', 'error');And this is route method. public function route($pattern, $callable) { $pattern = strtr($pattern,array(' '=>'')); if ($pattern == 'default') { $this->default_route = $callable; return $this; } $arr = explode('/', $pattern, 2); $method = $arr[0]; $route = '/'.$arr[1]; if (strpos($arr[0], ':') !== false) { $arr = explode(':', $arr[0], 2); $name = $arr[0]; $method = $arr[1]; } if ($method == 'MAP') { foreach ((explode('|', self::Methods)) as $method) { $this->route((isset($name)?$name.':':null).$method.$route, $callable.'->'.strtolower($method)); } return $this; } $this->routes[] = array($method, $route, $callable, isset($name)?$name:null); return $this; } This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=358535.0 Hey all, Wondering maybe someone can help me out, I am training to be a firefighter (I am not a coder) and am writing a little script for my local volunteer fire brigade to try help em out a little and I am stuck! It doesn't do much but grab the address out of a pager message but I have searched and tried a few ways to get this and now I am tired and just can't get my head around how to do this! Let me explain, Below are 2 pager alert messages and I have a sore head of a time trying to extract the address and job details of the second message into a php string using Expressions/Regex... Here are 2 example messages: Code: [Select] 0571040 15:45:21 30-04-12 @@ALERT F546356345 THEB8 STRUC1 SMELL OF SMOKE AND ALARM OPERATING 900 SOME ROAD SOMESUBURB /CROSSSTREET1 RD //CROSSTREET2 AV M 99 A1 (429085) CTHEB CBOROS PT28 [THEB] 0571040 15:45:21 30-04-12 @@ALERT F546356345 THEB8 STRUC1 SMELL OF SMOKE AND ALARM OPERATING 4 / 900 SOME ROAD SOMESUBURB /CROSSSTREET1 RD //CROSSTREET2 AV M 99 A1 (429085) CTHEB CBOROS PT28 [THEB] You will note the second address has 4 / 900 at the start or it could say Unit 4 / 900... and this is where my issue starts! The addresses can come in the 2 different formats, I have first one sorted with the code below but this address with no 4 / 900 some road just has me and my code below stumped. The extra / is just to complex a thing for me and my brain to handle! lol Please Help! As you can see I use the first slash as the first cross street but in the second case above the first / is now a part of the address... Below is what I have so far: Code: [Select] function get_string_between2($string, $start, $end){ $string = " ".$string; $ini = strpos($string,$start); if ($ini == 0) return ""; $ini += strlen($start); $len = strpos($string,$end,$ini) - $ini; return substr($string,$ini,$len); } $fullstring = "$rawPage"; if ( strpos($fullstring, ' STRUC1 ')!== false ) { $parsed = get_string_between2($fullstring, "STRUC1", "/"); } $input = "$parsed"; preg_match('/([^0-9]+)(.*)/', $input, $matches); $jobdet = "$matches[1]"; $jobadd = "$matches[2]"; Now this works fine for the top message and I get this as the result: $jobdet = SMELL OF SMOKE AND ALARM OPERATING $jobadd = 900 SOME ROAD SOMESUBURB $firstcrossstreet = /CROSSSTREET1 RD $secondcrossstreet = //CROSSSTREET2 AV For the second message it's all wrong with this the result: $jobdet = SMELL OF SMOKE AND ALARM OPERATING $jobadd = 4 $firstcrossstreet = / 900 SOME ROAD SOMESUBURB /CROSSSTREET1 RD $secondcrossstreet = //CROSSSTREET2 AV I know it's the / causing it but how can I make the code handle either case? Any help would be greatly appreciated! Thanks! This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=308051.0 This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=356424.0 |