Regular Expression :: Find Word Matches To Words In A Comma-delimited List
What's the *right* way to find word matches to words in a comma-delimited list. For example, if I have the following comma-delimited list of categories in a mysql db field:
gameboy, nintendo, playstation
and I do a search, I know I can use regexp to do something like:
select * from categories where regexp 'gameboy,'
Notice that I have the comma in there to match the whole word and the comma without matching part of a word (to prevent unwanted matches such as "play" to "playstation" or "game" to "gameboy"). The problem I'm running into is words that match that match the end of each word next to the comma (in this example, "boy" and "station"). What's the right way to match a word *exactly* using regexp *without* also matching *part* of a word.
View Complete Forum Thread with Replies
Related Forum Messages:
Regular Expression For Comma-delimited Pairs
I have a textarea form field for inputting (or pasting) pairs of data. I need a regular expression pattern to validate each line for the following double quote number double quote comma double quote alpha string double quote carriage return The following comes close, but doesn't check for a carriage return at the end of each line: ^"([0-9]?)+"([,]s?"([A-Za-z0-9]+)")*$ For example the following would return true: "1","John" "2","Paul" "3","George" "4","Ringo"
View Replies !
How Do I Find A Word In A Sentence From The List Of Words In An Array?
I have few list of words (needle) I want to find in a sentence (haystack). After a word is found, how would I echo that word? Is there a way to have a multi array so: if the sentence contains word1,word2 or word3 then echo "coding" if the sentence contains word4,word5 or word6 then echo "forums" <?php $title_of_the_item = "This would be the sentence being pulled."; $words_from_title = explode(" ", $title_of_the_item); $word = array("structure", "php", "sentence", "pulled"); if(in_array($word,$words_from_title)){ //even though two words are found in the array, use only 1 } ?>
View Replies !
Using The "preg_match_all" Function In PHP To Find Text That Matches My Regular Expression.
I have been using the "preg_match_all" function in PHP to find text that matches my regular expression. The php website documentation for "preg_match_all" states that "After the first match is found, the subsequent searches are continued on from end of the last match." The problem is that I want all possible matches, and do not want it to "start the subsequent searches from the end of the last match". Does any one know how I can achieve this?
View Replies !
Regular Expression That Will Split A String Into Several Parts With ',' (comma)
with a regular expression that will split a string into several parts with ',' (comma) as the separator, but NOT where the separator is enclosed in parentheses. For example, take the string "field1, CONCAT(field2,' ', field3) as field23, field4". I would like to be able to split this into the following: [0] field1 [1] CONCAT(field2,' ', field3) as field23 [2] field4
View Replies !
Regular Expression :: Replace The Words Documentation
I am looping through a document and for this example, I'm going to replace the words documentation and process. On the first loop, it replaces the word documentation with the following for a javascript tooltip: <span style=" border-bottom : 2px dashed #007700; cursor : help;" onmouseover="return escape('There is a process for documentation')">documentation</span> That works just fine. Now, the issue is, notice the word process in the tooltip area. On the second loop, it wants to replace the word process inside there with the same sort of code so it's creating something like <span style=" border-bottom : 2px dashed #007700; cursor : help;" onmouseover="return escape('There is a <span style=" border-bottom : 2px dashed #007700; cursor : help;" onmouseover="return escape('This is a process')">process</span> for documentation')">documentation</span> Now, you can see the issue, the span w/in a span that's within a JS call. Sure, this is all JS now, but, what I need is the regular expression to ONLY replace if there is NO <span> before it: <span style=" border-bottom : 2px dashed #007700; cursor : help;" onmouseover="return escape(' So, basically search the document for the next word(could be any) and ONLY replace the word if it's by itself and does NOT have the above before it. *NOTE: there can be any # of characters between the end of the above line and the beginning of the *word_to_be_searched*
View Replies !
Regular Expression For Word Myspace
PHP Code: <?php $text = 'This is a myspace test of m*ys_p a+c..e variations on the word MyS.p*a#CE. The end.' if(preg_match_all('/m[^a-z]*y[^a-z]*s[^a-z]*p[^a-z]*a[^a-z]*c[^a-z]*e/i', $text, $matches)) { echo "<p>Found these matches:</p>............. nogdog gave me this code and it works well I thought until now I found a flaw in it myspace and myspace with a space in it and with that space being any character is matched except if that space = a letter so mLyspace is not matched but m1yspace is.
View Replies !
Regular Expression With A Single Word
I have a problem regarding regular expressions. I take a string and explode it into an array using spaces so that every word is a separate element. I then apply several regular expressions on each word looking for certain patterns and replacing them. Code:
View Replies !
Regular Expression :: Find Between Pipes
I have a little problem getting a working regular expression for the following haystack: some text <|another text <| and another one|> the last one|> and this is the end. The regular expression should find the text within <| and |>. In this case it should find another text <| and another one|> the last one and <| and another one|> As you can see the pattern is nested. This one does not work, but this is obvious. PHP Code: preg_match_all("=<|((s|.)*[^|>]*)|>=U", $text, $um); Tried some more complex ones, tried some modified patterns to find HTML-Tags from Internet, but nothing worked.
View Replies !
Want Regular Expression To Stop At First Occurrence Of Word
I have the following string: $string = "list of whales: white beluga whale humpback whale atlantic humpback whale"; I want to pull out the first kind of whale (white beluga). I want this to work regardless of whether the first whale is a white beluga, or a humpback, etc. I tried: $regExp = "/(whales:)(.*)(whale)/"; $outputArray = array(); if ( preg_match($regExp, $string, $outputArray) ) { print "$outputArray[2]<br>"; } But, the output is "white beluga whale humpback whale atlantic humpback", as I expected. I know how to stop after finding a single character, but I can't figure out how to stop after finding a single instance of a word.
View Replies !
Regular Expression To Underline A Given Word In A Text...
With the sentence : "Bordeaux est au bord de l'eau" How to do to underline, for instance, the word "eau" ? without underlining the substring of "Bordeaux" ? I don't know how to isolate the word... My current code : $text=eregi_replace("(".stripslashes($word_to_underline]).")","<b> |