Help With Regexp Needed
Hello,
I'm coding a simple templating system to fit in to my simple CMS system. The way this will work is that the administrator of the CMS can edit the template (stored in a db), and insert 'snippets' into the template. A snippet is a piece of code (also stored in the db) which may have PHP code in it, which will then be eval()'d.
A simple example would be:
<html>
<head>
<title>[[title]]</title>
</head>
<body>
[[menu]]
[[content]]
</body>
</html>
The snippets here are [[title]], [[menu]] and [[content]]. This is fine as long as I know exactly which snippets will be in the template, but that's not always the case.
So what I want to do, is search through the string containing the template, find all the snippets and save these in an array.
My guess is that this'd be done with regular expressions, but I'm still very new at those, and have no idea how to do what I want.
Does anyone have an idea about how to do this?
Thanks!
Alex
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Regexp... Help?? Please....
I was trying to understand how this regexp work but the regexp reference is like written in chinese... anyway, what i'm trying to do it get all block between certain characters... like HTML... for example, i need to replace {b}text{/b} to <b>text</b>... this structure can have multiple levels like {b}stuff {i}here{/i} or here {html}<b>html</b>{/html}{/b} of course, i could just replace {b} to <b>, but how can treat html blocks between {html}{/html}... I'm sortof writing forum here and need such feature as my own markup language.... any help?
Need Help With Regexp
I would appreciate if someone could take a look at this and tell me what I am doing wrong with the regexp. No matter what I do I cant seem to get it to display both int without it displaying the preceding '(' Anyhelp would be great. Function Printthis() { $url = "test.txt"; $fp= fopen( $url,"w+"); $charSta = "document.getElementById("agi").style.color=getColor(18); preg_match_all('!document.getElementById([^>](.*?)").style.color=getColor([^>](.d+))!is', $charSta, $matches); for($i=0; $i<count($matches[0]); $i++) { $match1 = $matches[1][$i]; $match2 = $matches[2][$i]; fwrite($fp,"$match1= $match2"); fclose($fp); echo "&$match1= $match2"; } } echo (Printthis());
Could It Be Done With REGEXP?
After reading the explantion about regexp and perc in the php manual twice i am still having problems with the entire thing. as long as "simple" regexp everything is fine, but this time i have something which i m not sure is at all possible but i think its worth asking. this is how it goes: i have this string (with unknown length could be 0 and could be anything other than 0), retrived from a database. in order to make it readable i need to add the <br> tag since the text was originally entered by the textarea. in order to do that nl2br would be good engoth BUT... i need to limit the text so that when it is echoed to the html page, it will contain the <BR> tag where it should be ( instade of the " ") and check to make sure that the length of each line is no more than 50 characters. if there is no for 50 characters then i should add the <BR> tag in order to continue in a new line. now again a problem if the place where it gets to the 50th character is somewhere in the middle of a word then the word itself should not be cut in to two, but be moved to the next line.... that does make sence right? i know i can do it using a for loop and echo each word after counting the total characters from the last BR but i was wondering if there is any better more elegant way of doing it?
Need Help With An REGEXP
I am unfamiliar with regexp. I found this piece of code and am just trying to see how to modify it:
Regexp Help..
I am trying to extract the headlines/url's under the "technology" gif at http://www.techweb.com/newsPopUp/content I am using: preg_match_all("/<a href="http://www.techweb.com/wire/story(.+?)">(.+?)</a>/i", $page, $news, PREG_PATTERN_ORDER); This SHOULD work (I think), but there seems to be a problem in receiving the first (.+?). The second, which is the headline is received fine.
Regexp
$html="<b><a href="url">somthing</a><br><a href="url">somthing here</a>"; What I need to do is collect all the html links inside a string (<a href="url">somthing</a> ) and add them to an array.
Regexp
I am having trouble with the following. I'm not getting any error and I have exhausted everything I can think of so any help would be appreciated. I am trying to get whats between the <td></td> tags. It needs to start at the HP because it is just a segment of a larger string. Itried a bunch of different combinations but the following 2 didnt return any errors, just not the data I want. <td>HP</td><td>2132</td><td>210</td><td>99</td><td>2441</td> preg_match_all("/HP(<[.+]>)+([d+])</[.+]>/si",$file,$matches); preg_match_all("/HP(</?[.+]>)+([d+])</?[.+]>/si",$file,$matches);
Regexp
I think I am need of a regular expression with regards to a str_replace need that I have... I have a string like this one... "text text text{ text } text {text text } t {text} txt { text }" I need to replace all occurances of "{" with "{ " and "}" with " }" where the following rules apply... replace "{" with "{ " when the character to the right of "{" is NOT <newline> and is NOT <space> and is NOT <tab>. replace "}" with " }" when the character to the left of "}" is NOT <newline> and is NOT <space> and is NOT <tab>. So, the result in my example above would be.... "text text text{ text } text { text text } t { text } txt { text }"
Regexp
Say I have a list of 3 key words: 'mi go home'. Then user enters into a search such as 'm go home' that I will assemble them into a regexp such as [(m)(go)(home)] I would like to REGEXP in mysql to see if user enter any word matching keyword list by select ... searchwordField REGEXP '[(m)(go)(home)]' 'go' and 'home' match, but 'm' should not 'mi', but it did. How to use REGEXP correctly?
RegExp
I have this string (html code) <LOOP loop1> <tr><td>some code</td></tr> <LOOP loop2> <tr><td>more code</td></tr> <ENDLOOP> <ENDLOOP> I want to extract the "loop1" string and everything between the <LOOP loop1> and the second <ENDLOOP> including the the other <ENDLOOP>. On a second pass extrat the "loop2" and all the rest between the <LOOP loop2> and the first <ENDLOOP> I'm using this PHP code to do it: $loopregexp = "/<LOOP (.*)>(.*)<ENDLOOP>/Usi"; while (preg_match_all($loopregexp, $code, $loopieces)) { for ($i=0; $i < count($loopieces[1]); $i++) { $loopname[$i] = $loopieces[1][$i]; $repeatcode[$i] = $loopieces[2][$i]; }} For the example above, in the first pass, $loopname[0] would get the "loop1" and $repeatcode[0] would get everything between the <LOOP loop1> and the last <ENDLOOP> On the second pass, $loopname[1] would get the "loop2" and $repeatcode[1] would get the code between the the <LOOP loop2> and the first <ENDLOOP>. I can't make it work, because the regexp stops at the first <ENDLOOP>. How can I make it includ it and stop only in the last <ENDLOOP>?
Link Regexp
I am try to get all the links out of a document with a regexp.
MySQL REGEXP
In the MySQL docs you can read the following: Quote:[[.characters.]] The sequence of characters of that collating element. The sequence is a single element of the bracket expression's list. A bracket expression containing a multi-character collating element can thus match more than one character, for example, if the collating sequence includes a ch collating element, then the regular expression [[.ch.]]*c matches the first five characters of chchcc. Link to MySQL REGEXP documentation I tried this query for example: SELECT "Dois helicópteros foram dados como desaparecidos devido às tempestades" REGEXP "[[.devido.]]"; It won't work Am I doing anything wrong? I'm trying to substitute «LIKE» on a search query. Fulltext search won't do the trick since I require exact control over the results obtained and the MySQL database version in use is prior to 4.xx After I finally figure out how to REGEXP the hell out of it, the next problem will be how to escape special chars from the variable that will be passed into the REGEXP. example: $query="select somecolumn from sometable where somecolumn REGEXP "[[:<:]][[.$searchstring.]][[:>:]]";" // obviously, the $searchstring has to be escaped for regexp special chars before being used in the REGEXP query .
Regexp Question
I have a text and I want to match several words like this "(controller| data|IT)?" at least one of the words in the group should be mandatory, but I dont want to match a word that is part of another word like this "datamanager" it should only match the word "data" or any other word in the group. Any suggestions?
Regexp: Right Patternt For The Following ...
I am looking for the right pattern to grab the following HTML text: "<a href="http://www.genericdomain.com">Text Text Text</a>" and to exclude the following: "<a href="http://www.genericdomain.com"><img src=image.gif></a>" At the moment, I use this pattern: "<a href="(.+?)">(.+?)</a>" that grabs both the previous strings.
Regexp Question
I have a regalar expression to extract an html link from a page: href=(["']?)([^>1]*.html)1(?: [^>]*)?> It looks after the "href" for an optional quote and then looks for something that is not the quote or the endarrow. The problematic part is [^>1]*. It should exclude anything with the quote, but somehow that doesn't work. Maybe 1 is not allowed inside brackets? I would like some advice on how to handle this.
Regexp For Site Url
I would need a code that checks if an url with filename is valid or not. Here are a few examples: http://www.example.com/file.zip (valid) http://example.com/file.zip (valid) http://www.example.com/files/file.zip (valid) ftp://ftp.example.com/file.zip (valid) ftp://example.com/file.zip (valid) ftp://ftp.example.com/files/file.zip (valid) http://www.example.com/ (not valid) http://www.example.com (not valid) www.example.com/file.zip (not valid) ftp.example.com/ (not valid) ftp.example.com (not valid) If anybody knows a regexp for this please share with me!
POSIX RegExp
How to match any string which does not contain a specific substring? Example I want to match all strings which do not contain the substring 'foo'
Regexp And Preg_replace
I'm making an admin section for a site in which I'm using [UBB] type tags (which I'll display from here on as {UBB} so they'll show up) which I then need to parse in my script. I ran into a bit of trouble because I am using a {url=}{/url} and I also want anything the user types that begins http:// or www. to be automattically made into a link. I can do each of them individually, but when all three types are on the page together, the regexps I have written start to step on each others toes. My thinking is (and yes, I have no doubt it's flawed thinking ) that I should be able to grab the http:// and www. links and parse them before I run through the {url=} tags to parse them, but the way Ive tried it doesn't seem to work. Here's an example of the regexp I've tried that I want to grab anything begining with http:// or ftp: ect but not if it has "[url=" at the front of it. $description = preg_replace("/[^([url=)]([a-z]+?://){1}(([a-z0-9_-/]*.)?[a-zA-Z]*.[a-zA-Z]+ ?)/i", " <a href=12>12</a>", $description); But this still gets the links that are within the {url=} tags. I hope I have explained my problem well enough for everyone to understand.
Struggling With Regexp
im trying to create a regexp that will work on data that is arranged thusly: 92291A , C92291A , 140191A , REM92291A this data comprises of any number of model names with a space, a comma and a space delimiting them and a space at the start and end of the string. i wish to be able to remove any one of those elements and still retain the arrangement of the data and delimiting.
MySQL LIKE/RegExp
I have a table with a column that contains many names, like "Ant Simon Lucy", if I was looking for one name in the string of names I would do... SELECT * from classroom where name LIKE '%ant%'. But the select above will return rows with names like 'antoine' or 'anthony'. So I guess I could have a select with spaces... SELECT * from classroom where name LIKE '% ant %'. But that also does not work if 'ant' is the first or last entry in the list, (like in the example above). So to solve my problem I would need something like... SELECT * FROM classroom WHERE name LIKE "ant %" // first item in the list with more OR name LIKE "% ant %" // neither the first nor last item in the list OR name LIKE "% ant" // the last entry in the list OR name = "ant" // the only entry in the list But that does not look right, it does the job I guess but not in a very elegant way. Can someone give me a RegExp that would look for an exact name, (case insensitive), in a string of names. And how would I escape special characters in the string itself, (in weird cases where the name I am looking for is something like "An^t"
Help: Site Search With REGEXP
Hi, I have been working on this for quite some time now; I am doing a mysql search and need some help. I started out with %$search_string% but that would return inaccurate results ... so after doing a whole lot of reading and trying a bunch of different combinations of REGEXP I got pretty close with [[:<:]]$search_string[[:>:]] but I think I can make the search even better if I search for all words that begin with a single special character end with a period, comma, hyphen, prentice etc. After trying some combinations I’m not getting far, what I need to come up with is a REGEXP Class such as [^|-|,|(|)|.]$search_string[$|-|,|(|)|.] unfortunately this doesn’t seem to do anything. I can’t find any good references on how to make classes like that. Please help.
Validating A Surname - Regexp Fu
I seem to have got myself into a tangle with a bit of regexp work. I need an expression which can be used to validate a surname, ie it will allow a-zA-Z , single spaces, hypens (-), single quotes (') such that the following are passed: Jones O'reilly Langly-Smith Van Schnee preferrably using PCRE syntax, with POSIX [:alpha;] - type expressions if needed. anyone got such a regexp lurking?
Regexp To Get Data From Flatfile Db
I was given an application with existing data to migrate into a new application that I wrote without knowing of this data. Consequently, I now have the difficult task of extracting the data and putting it where I need it. The data exists in a text file in the format: Code:
Regexp With Non-english Characters
Sometimes when my users are from non-english speaking countries and they enter something in non-enligh language, the text goes into my database as something like this -- Quote: ジャパンインク,日本のITビジネス,Eビジネス, I dont know what kind of code this is, but does anyone know how to trim all these junk characters, or to convert them into the right looking characters from what these are right now? I can change my encoding to Shift_jis or big5 in the browser (japanese and chinese) but these characters still look like this. 1. How can I erase these from the text? I dont know regexp but my thinking is that if something matches the pattern: & # 1 2 _ _ _ ; & Then I can delete it? 2. Even better, does anyone know how I can encode these characters back into their respective language?
Regexp Question Dealing With '
hi guys, I am trying to check US City names using ereg and I have tried eregi also. the only problem is when i get a submit that has a ' for instance O'Hare the ' gets rejected and the out puts a slash next to the '. here is the code for the city check if(!(ereg("^([[:alpha:]]+([.¦-]?[[:space:]]?[[:alpha:]]+){2,})$", $_SESSION["city"]))) { //do what I want here } the whole code is on one line and it works perfect but when I change the code to this... if(!(ereg("^([[:alpha:]]+(['¦.¦-]?[[:space:]]?[[:alpha:]]+){2,})$", $_SESSION["city"]))) { //whatever I want goes here } the code doesn't work and the output is displayed like this...... O' Hare i tried removing the slashes with the stripslashes to the output, but that just fixes the output but I still go in the if statement. I tried it with only one slash as well but same result. What am I doing wrong. why can't I escape ' should I use something else other than ereg or eregi. Thanks in advance for your help.
RegExp : Using End-of-line In A Pattern
I would like to get field values from a multi-line text. For instance : " Name: Mr Smith Address: Paris " I've tried to use (I'm a total regexp newbie, so I took it from the doc): eregi("Name: (.*) ",$VariableHoldingTheText,$parts); Problem: $parts[1] starts at the right place, but does not stop at the end of the line. I get : "Mr Smith Address: Paris " Where am I wrong ?
Regexp Phone # Check
I'm working on validating US phone numbers. I have a nice expression that Regex Coach likes, but causes PHP to reject everything I send. Are there any glaring differences? I can't figure out what's wrong. Another little email check works fine, using the code out of Wrox' Beginning PHP. PhoneCheck.php <?php function PhoneCheck($number) { return ereg("^[([]?d{3}[)-.] ]*d{3}[-. ]?d{4}$", $number, $scrap); } ?> My test cases (which passed regex coach, but failed my php form): 123 456 7890 (123) 456-7890 123.456.7890 123-456-7890
Non Display Able Characters In A Regexp...
I'm having some odd issues with preg_replace...I'm trying to replace any unusual nondisplayable characters (everything with an ordinal less than x32, except CRs, LFs, and tabs), but the regular expression that would normally work in perl doesnt seem to be working in php. I assume I'm missing some subtle language difference...This: <?php $string = "Testing x01...x02...x03..."; $result = preg_replace('/[x01-x08x11-x12x14-x31]/', 'X', $string); echo "{$result}"; ?> Should produce "Testing X...X...X...
POSIX Regexp Predefined Classes
Does anybody know a website that lists a complete list of the predefined classes of POSIX regular expression? (i.e. [[:space:]]) I find a lot of references for PCRE, but I haven't been able to locate a comprehensive reference for POSIX reguar expression. PHP.net has a section for POSIX regular expression, but it does not seem to offer a list of predefined classes (or maybe I am missing something)
RegExp To Split HTML-File
Following might sound a little dumb but it seems I am not capable of understanding regular expressions at all. I am building a template system in php. works all great so far. Now i am trying to implement files into a template and need to find out a few things. So here is where I stand: I have a complete html-file in a one-line string. now I want to extract 3 things from it using preg_replace. 1) anything between <head> and </head> EXcluding <title> and <meta> tags. 2) any parameters in the body-tag which are event related. e.g. onload onunload onclick etc. but not styletags and no things like bgcolor and stuff either 3) everything between <body> and </body> I plan und putting it together in a string like and then explode it to have all 3 values in an array. like: $result = "1*#*2*#*3"; $data = explode("*#*",$result);
Matching User Inputed Regexp
I'm using php and have a complicated task, so if someone can understand it then please help me to solve it The task is to make function, that will understand user-inputed regexp and perfome some actions with inputed regexp. For example: 'categories: ".*" -"foo"' means "all categories, but not 'foo'" 'categories: "foo[a-b]*" ".*bar"' The regexp are not case-sensitive. A '-' (dash) preceeding a categoryname means "do not select this category". Here is the function that is ok for ".*" but not for ".* -foo": function cheaker ($string ,$patterns) { $patterns_list = explode(" ", $patterns); foreach($patterns_list as $cs) $res = eregi($cs, $string, $regs); return $regs[0]; }
Multiple Line Regexp Matching
I need to match anything but multiple line (trhu and ), my regexp is: "/<!--{([A-Za-z0-9]*)-->.*<!--1}-->/" (Perl compatible), the problem is that the .* won't match multiple lines, in Perl and sed there are modifiers to make .* match multiple lines,, are they in php, or how should I do this ?
RegExp For Removing Text Between Parenthesis
I have a string like this: GeboGebo Wiki 0.9.2 (Default branch) I want to remove the words between the parenthesis. I tried this regexp: /([a-zA-Z0-9])/ but without success, what is wrong with it ?
RegExp That Looks For A String And Only Replaced Part Of It...
I'm after a regular expression that looks through a string for a certain code, and then replaces part of that code with some markup: So look in this string: this text contains (T123) a code. And become this string this text contains (T<a href="?a=123">T123</a>) a code. The main problem I'm having is that my regexp replaces the whole match, including the T: $pattern='(T[0-9]{3})' $replace='<a href="?a=1">1</a>' This results in a hyperlink "?a=T123" when I want ?a=123
How Would I Write A Regexp On A MySQL Query
Using PHP 4 and MySQL 4, how would I write a function such that it takes a valid MySQL query, and a column on which to order the query, and return a new query ordered by that column? $query = formNewQuery($query, $orderByCol); An assumption you can make is that the query will never have multiple columns on which to order -- e.g. ("ORDER BY COL_A, COL_B"), however the query could contain the "DESC" keyword -- "ORDER BY COL_A DESC".
Regexp, Mysql And Plural Marking
for a search engine, I'm looking for a regexp than can do the job it is just (!) a 's' problem (frequent in french) : I have a field 'thesaurus' in a table MySQL (3.23.56) ; I have a field 'search' in a form where user can input a word ; what I want is : if search == 'mil' return 'mil' (if exist) AND 'mils' (if exist), but do not return 'military', 'million','milsblabla',... if search == 'mils' return 'mil' (if exist) AND 'mils' (if exist) but do not return 'military', 'million','milsblabla',...
Regexp To Find The Subdomain (if Any) From $HTTP_HOST
I need creating a regular expression to find the subdomain in the $HTTP_HOST variable. The domain is always in this form: www.domain.com or uk.domain.com or domain.com there is no such thing as a sub.sub.sub.domain.com (not in my case, at least)
Regexp: Not Matching A Sequence Of Characters
and this may be a rather dumb question, but so far I haven't found the answer in any tutorial or reference yet... If I have f.i. the string "The {{{{power of {{{{regular expressions}}}} comes from}}}} the ability to include alternatives and repetitions in the pattern." from which I want to extract chunks starting with "{{{{" and ending with "}}}}". When I use "/{{4}((?s).*?)}{4}/" as the pattern, it matches "{{{{power of {{{{regular expressions}}}}". What I want is for it to match "{{{{regular expressions}}}}", so somehow I should be able to avoid having "{{{{" contained in the subpattern. Exclusion, afaik, only works with character classes and not with with sequences of characters. I could make the the subpattern exclude the "{" character as in "/{{4}((?s)[^{]*?)}{4}/", but this does not satify my needs because I want to avoid the occurence of having 4 accolades, no more no less... so, how would I have to write the pattern to exclude a sequence of specific characters, rather than a character class?
Ereg Regexp Problem - Matching A Dash(-)
I have a problem of matching a dash(-) in the code beolow. Why does not the below work when matching a dash(-) but all other signs is correctly matched when trying?
Ereg - Regexp For NOT Matching Certain Filename Extensions
Is there some way of using ereg to detect when certain filename extensions are supplied and to return false if so, WITHOUT using the ! operator before ereg () ? I have an API that allows as an input a regular expression, enabling the administrator to ensure a file upload matches a certain pattern. For instance, supplying the string '.exe$|.com$|.bat$|.zip$|.doc$' means that the file must end with any of these five extensions. Is there a way that the regexp could be rewritten to say that the file must NOT end with any of these, without changing the ereg to !ereg - I can't do the latter because it's within the class.
Splitting Merged Words But Www Adresses (regexp)
Is there any way to split all merged words but www and e-mail addresses? I have regexp preg_replace("/(.)([[:alpha:]])/", "1 2", "www.google.com any,merged.words mymail@domain.com") it give me incorrect result: www. google. com any, merged. words mymail@domain. com i need result www.google.com any, merged. words mymail@domain.com in my case, all web addresses has www. or http:// in beggining of string and email of course @ inside string is it possible to write regexp like this?
Replace Text Outside Html Syntax Regexp Php
how can i replace text outside a html syntax by using reg exps in php? I mean i have a text like <h3>heading</h3> <p>text</p> <table> <tr> <td>cell1</td> <td>cell2</td> </tr> </table> or any html code. now i want all the text outside the syntax (here: heading, text, cell1, cell2) replaced by a special code like <img...>. how can i code a reg exp pattern in php, that replaces each character in the "real text" by an other piece of code, but doesnot change any of the syntax statements?
Valid MySQL Database/table/column Name Regexp
regular expression in PHP which could be used to check that a proposed (My)SQL database/table/column name is valid, i.e. shouldn't result in an SQL error when created? The user of my (hopefully to be opensourced) program has the ability to create database/table/column names on the fly. I'm aware of obvious characters such as ., [space], things like >, etc., which won't work, but haven't been able to source a definitive list, including having googled the MySQL site. Obviously certain characters need to be filtered out, as noted above, but I want to be as unrestrictive as possible; hence just [a-z]* isn't good enough because things like _ are acceptable. Ideally, I'd prefer a regexp that applies to _all_ vendors' databases, not just MySQL as I'm about to migrate the program to being database-independent, probably using PEAR DB, but even a MySQL-specific regexp would do the job. In the longer term, I plan some sort of entity conversion script so that theoretically any character could be used, using some sort of escaping mechanism probably.
Help Needed..
I am Ronny from Germany, so please excuse my English. Since early 2002 I am trying to solve th following problem: I am trying to programm a meta search engine - which fetches the results of about 10 search engines. Now I solved the problem with fopen(), fread() etc. But it is to slow - and so my question is : Is it possible to make several http requests at the same time in PHP or do you know a Perl Program where I can put in maybe 10 URL´s and the results where saved in an array which I can use in PHP???
NOW() Help Needed
I am putting data into a mysql database, the database tells me the time a user signed up, this is placed in the table using the now function but the date always shows as 2002/11/06 not how i would like it, i want it to view as 06/11/2002, i think it can be manipulated in many ways. Also on manually updating a further table i have to place in a date manually, when i put the date in the fiels using phpmyadmin the date still looks like 2002/11/06, i try change the value but with no joy.
PHP Developers Needed
hello, My name is Joshua Abbott and I am project administrator of the AWHCP project on sourceforge.net. Our project is aiming to create an advanced web hosting control panel of 350 end user features (once final release) and a lot of security features in a packaged OS called extremeserv-linux @ extremeserv-linux.com . We desperately need PHP Developers to help in this endevour. So, if you are interested or want more information please email URL
Help Needed In Sending SMS With PHP
I want to know the process and the Implementation of sending text SMS to mobile phones with PHP. Is there any article regarding this? or any code example?
Nusoap & XML Help Needed
I am getting below result when accessing a web service. Now how can I separate the values and assign them in variables for further use?
|