Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    PHP


SuperbHosting.net have generously sponsored dedicated servers to ensure a reliable and scalable dedicated hosting solution for BigResource.com.





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 !
Regex Problem - Regular Expression That Matches Any Double Letters In A Word
I am trying to figure out a regular expression that matches any double letters in a word. For example,

Look (the double o's)
connect (the double n's)

I think it might be pretty simple but it is baffleing me.

View Replies !
Regular Expression To Find A Specific Word In A Body Of Text?
What would be the regular expression to find a specific word in a body of text, while also making sure it is not a linked word already?

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 !
Easy Comma-delimited List To Dropdown Box Converter
I was working on a simple converter when I realized that by not setting the id param of the option tag, it wasn't going to send the value of the dropdown box to my php script. I had this to start with: Code:

View Replies !
Get The Regular Expression Which Matches Text Between Two Underscores
I'm trying to get the regular expression which matches text between two
underscores: _MATCHTHIS_

The problem is, I don't want to match it if the only thing in between
the underscores are spaces or other underscores: Code:

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 - Not Letters - Words?
I need a regular expr. that would match any expresion that doesn't start
with some words (not letters - words!)

For example - reg. expr. that matches any expression that doesn't start with
words 'one' and 'two'?

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></b>",$
text);

but this underline "eau" in "Bordeaux" too and i don't want to !

View Replies !
Regular Expression :: Fina The Word In A String
I have this string:

$string = "Life Is Great with Brooke Burke LIG 101 Big Spender";

I want to find if the word 'Big' is in this string.

View Replies !
Regular Expression :: Find Either A^ Or O^ In A Block Of Text
I want to find either a^ or o^ in a block of text, and replace them with &acirc; or &ocirc;. I've tried this but it does not seem to work: PHP Code:

function checkAccent($text){
        $pat[0] = "/^a^$/";
    $pat[1] = "/^o^$/";
    $rep[0] = "&acirc;";
    $rep[1] = "&ocirc;";
  echo preg_replace($pat, $rep, $text);
    
}

View Replies !
Regular Expression To Scrub Text Copied From Word
I am trying to build a regular expression to scrub some incoming text to remove stuff that comes into the WYSIWIG editor from Word (even though we explicitly tell the users to copy their text into Notepad first). Code:

View Replies !
Regular Expression :: Check To See If The String (a Single Word) Is Mixed Case
I'm trying to get a preg_match() to check to see if the string (a single word) is mixed case. Specifically i need to check if:

1) the word has more than one uppercase character in it
2) the word is more than two characters
3) one of the uppercase characters must exist as the first character in the word.

View Replies !
Regular Expression, Validate A List Of Numbers Separated
I need a regular expression that validate a list of numbers separated
by "-" , numbers can not be greater than 999
Valid examples
0
12-455-01
1-9
125-32-155-45-45
Invalid examples
-1
45-
1-45665456-4
12-45-
-
.......

View Replies !
Comma Delimited File
I am trying to read comma delimited rows of text. The problem is that
some fields may be encapsulated in "" - particularly the text fields but
not numeric fields.

Is there a simple efficient way to parse the fields with comma but also
strip off the "" encapsulating some of the fields with php?

The problem is the "" encapsulation is optional. Some fields will have
it, some won't.

View Replies !
Statement With Comma Delimited Fields
I'm hacking into my vBulletin forum to use individuals current usernames, passwords, and membergroups to setup a premium portion of my site. I have the following query: PHP Code:

$users = mysql_query("SELECT * FROM user WHERE username='$username' AND membergroupids=&#3932;'");

With this query my login works for those who have signed up for the premium content on the forum. One problem is if the members join multiple user created member groups, they're membergroupids will be like 32,10,34. I need my query to find if they belong to 32 and if so allow them access. So, if they belong to 32,10,34 then they should be allowed to enter, but if they belong to 10,34 they should not.

View Replies !
Looping Through Comma Delimited String?
I'm wondering how I can loop through a comma delimited string in php?

my string: $string = "12499, 12498, 12497";
though the size will change depending on the query.


View Replies !
Comma Delimited Csv Has Commas Inside Fields
I need to import a CSV file into a database daily. That operation in itself is simple enough but the trouble is that some fields are quoted because they have commas inside them. How do I handle this with my import script?

It would be much better if the CSV was created with all fields quoted or used a different delimited but sadly that is not an option.

View Replies !
Reading Excel To MySql Or Comma Delimited ...
right direction on how to deal with an xls
flie.

but the only other file I have to work
with is pdf.

I'm not sure, is xls the better of two evils?


View Replies !
Stripping Quotes Out Of A Comma Delimited File?
I have a flat file that I'm trying to stick into a MySQL database. One
record per line, multiple fields per record, and many of them are null
fields which are just double quotes without a space between. It's probably
nothing really major for people who have done this before, but I'm a bit
stumped. The file is comma delimited. Every field is surrounded by double
quotes. I've done quite a bit of searching, on the php site and elsewhere,
but I can't seem to get it to strip the quotes out so I can explode the file
line by line to grab the fields.

View Replies !
Set An Array = To A Comma Delimited String Of Strings
is there anyway I can set an array = to a comma delimited string of strings and then loop through each of those manipulating the string. help me with the basic code for setting up the array and looping through it.

View Replies !
Converting Comma Delimited Field Into Array
I have an array that goes into a MySQL database (via PHP). The only way I could find to insert them into the database was using implode. It goes into the database just great, comma separated (although I would like each to go into it's own field, but it's okay for now).

The problem comes when I try to display it. Since it's comma delimited it display only the first item in the array. But there are multiple rows that should be displayed.

I'm not sure how to explode it so that it will display them all. I've tried a loop but that just looped the first item in the field (the first part of the array). Code:

View Replies !
Regular Expression :: Match A Word, Not To Match If It Contains Certain Surrounding Text
I need to look to see if it appears in a page, but not count its appearance in the page footer. How can I match a word, and specify not to match if it contains certain surrounding text? EG:

I want to match "foo", but not when the match is "only by foo".

I tried a few derivations of /[^o^n^l^y ^b^y] (f|F)oo/, but if the last letter of the previous word matches any of those letters, it doesn't work.

View Replies !
File Parsing Function For Tab Or Comma Delimited Files
I need a way to parse a file based on the delimitation of either tab or comma. Does anyone know the best way to do this that is the easiest? Also the file I am parsing might have a few empty strings between delimitation. I know about preg_split so if this is the only way could someone provide a link that explains regular expressions because i dont get it.

View Replies !
Create A Comma Delimited String That I Can Convert To An Array Using Explode();.
I am attempting to create a comma delimited string that I can convert to an array using explode();. I have the following code: Code:

$cPath_new_a = tep_get_path($categories['categories_id']);
$cPath_new_b = str_replace("cPath=", "", "$cPath_new_a");
$cPath_new_c = str_replace("_", "", "$cPath_new_b");
$cPath_new_d = substr("$cPath_new_c", -2, 2);

$cPath_new_e = $cPath_new_d . ",";

echo $cPath_new_e;


This outputs 23,53,

I need it to output 23,53 Using the substr($cPath_new_e, 0, -1); and/or rtrim() method to remove the last character for some reason removes all of the commas. Am I approaching this the right way?

View Replies !
Regular Expression That Will Find A Certain Text Between <abbr></abbr>
I want to create a regular expression that will find a certain text, and put <abbr></abbr> tag around it.

The hard part is, i want it to NOT do it to text that is inside of a link tag here is an example:

< a href="wsu.php" title="WSU">WSU</a>

i want to do this:

< a href="wsu.php" title="WSU"><abbr title="Wayne State University">WSU</abbr></a>

View Replies !
How Many Matches Of X Word In Message?
I have tried learning preg_match & preg_match_all, but its no use, can anyone make me a small piece of code that would count how many times x word was found in x message?

View Replies !
Regular Expressions :: Get The Lines Delimited By The # Symbol
I'm trying to get the lines delimited by the # symbol using regular expressions:....

View Replies !
Find All The Matches In A Table Between 2 Specific Dates.
I need to find all the matches in a table between 2 specific dates. For example, on each date, a certain airplane may be available for hire. But there are 4 airplanes. So on any date, there could be 4 planes available. Sometimes 1 or 2 of them are booked and not available. What i would like is to do a query, between 2 date ranges, and find only those airplanes available for all the days (say someone wants to go on a 5 day trips). What I have, but isn't working is this:

SELECT distinct t.tid
FROM dates d,types t,planes p
WHERE p.oid=d.oid
AND d.timestamp>$start_day
AND d.timestamp<$end_day
AND p.oid=$flight_school_id
AND t.max_persons>=$max_people
AND d.tid=t.tid
GROUP BY (t.tid) HAVING count(*) >= $nights
ORDER BY d.timestamp ASC";

View Replies !
Create List Of Matches!
i list how many times a word appears in some text and create an array of them. so if the text contains 3

<a href='whatever'>whatever</a>
i can create a list od the 3 results at the top;
1<a href='whatever'>whatever</a>
2<a href='whatever'>whatever</a>
3<a href='whatever'>whatever</a>

search text goes here. search text goes here. search text goes here. search text goes here. search text goes here. search text goes here. search text goes here. search text goes here. search text goes here. search text goes here. search text goes here. search text goes here.

View Replies !
MySQL: Searching With Joins Or Delimited List
I'm trying to implement a solution where a given company can set a list of the coutries in which it has branches.

My first thought is this:

'company' (id, co_name)
'location' (id, co_id, loc_code)

And when the customer want to know if a company has a location in Belize:

select c.co_name from company c left outer join location l on l.co_id = c.id where l.loc_code = 'BZ'

My second thought is adding loc_code to company: Code:

View Replies !
Re Comma Separated List - Another Question
I can do the match perfectly but what i also need to do is create a third
list of comma separated values that are in both

eg:

List 1 => 1,2,3,4,5,6,7,8,11
List 2 => 1,3,4,5,6,7,10,23

Therefore

List 3 => 1,3,4,5,6,7

How do I populate this third list - I'm really stuck ....

View Replies !
Breaking Up A Comma Seperated List
i have a list seperated by commas: 1. 3. 5. 7. 9 actually is a varible

$members ="1, 3, 5, 7, 9"; what would be the best way to break that up to insert the values into a table in a loop.

View Replies !
Comma Seperated List Comparison
is it possible to compare acomma separated list aginst another

eg comma list 1 => 1,2,3,4,5
comma list 2 => 3,5
can you check that 3 is in both, and 5 is in both, therfore they match?

the comparison is to check that if product a who supplies products 1,2,3,4,5
can be used instead of product b who supplies 3,5 as product a already
supplies them

View Replies !
How To Remove Last Comma From A Multiple List?
I have a multiple select list in my site where the values are inserted in a database table, in a column named available_country. I enter these values in the db separated with comma. I don't know however how to remove the last comma so it will be something like this:

USA, Europe, Asia

and not:

USA, Europe, Asia,

Here's what I tried but it didn't worked: ...

View Replies !
Meaning Of Comma After Bracket Eg. List(, $value)
i cant find what this means when you have a comma after a bracket as in for example

php list(, $value)

anyone could explain why that comma is there or at least what its called so i can read about it?

View Replies !
Comma Separated List In MySQL Field
say I have a list of categories in a field, and a page that is supposed to pull from the db based on a category. Is there any way I can do a query where it searches the contents of that field for the category in question?

like SELECT FROM table WHERE category = $category  but have it search the category field (the comma separated list for each entry) for the $category var

View Replies !
Array Form A Comma Delineated List
What's the best way to create an array from a comma delineated list?

I have a string assigned to a variable that looks like this: 1,2,3,4

And I would like to create an array so that $arr[0] = 1 and $arr[1] = 2 etc.

It seems so simple but I just can't crack it.

View Replies !
Count Words In Word File
How can I count words in a word file using PHP? The answer should match the wordcount of that particular word file.

View Replies !
Replace A Word But It Replaces All The Words.
I'm trying to replace a word but it replaces all the words. I'm basically trying to block bad words. Yes, I did ask for help about this before but still never found out how to do it  .

$Bad = array('fuck','shit','porn',
             'pussy','cock','dick',
'sex','nigger','cunt',
'ass','drblock','dr-block',
'sucks','suck','crap',
'pron','anal','cornhole',
'butthole','asshole','tit');

$request = ucwords(strip_tags(str_replace($_POST['textfield3'],'$Bad','panda')));

View Replies !
Find Non Hyperlink Words
I want to find all the non hyperlinked words from a given set of paragraphs. The words can be inside other tags like bold or italics but should not be inside an anchor tag. Currently using the following regular expression to find the word "keyword" :-

[^>]keyword[^</a>]

But it still matches the word "keyword" inside <a href="http://example.com">abc keyword xyz</a>.

View Replies !
Preg_replace: 'words' Beginning With Pattern --> New Word
I cannot seem to wrap my brain around preg_replace. Though I've read
the help file backwords and forwards. :/ Hoping someone can give me
a solution here.

Problem: Given string 'str' which may contain new lines and will
contain html code, IN this string any "words" that begin with an
underscore I want to replace with a given word. A word here being a
group of chars preceded by a space or null (start of line) and closed
by a space or null or htmltag start<. (Hope that makes sense.)

My current solution/hack:
$str=str_replace( array('_m<br />','_mt<br />','_t<br />'), ' ',
$str);

This is *a* solution, IN THAT I am manually entering into a db the
values _m _mt _t and then, this str_replace will take them and
replace them with a space. Ok, good so far. But I would LIKE to
be able to add new values to the db (ie _x _y _z _example _s7 )
and have THOSE be replaced by a " ".

However this is not the *best solution, obviously. I'm sure it can be
done with preg_replace. I hope!

Other things to note... in the string there are other <br /> tags
which are NOT preceded by a target word.

target words begin with a _ BUT if that is a bad character to choose
it can be anything you want, within reason. *g* In otherwords
starting them with a < would be bad (probably, given my limited info),
and starting target words with an alpha character would be bad because
there are other 'words' which are NOT targetted that begin with alpha.

So... could anyone help me here? If you feel like adding an
explanation as to why your preg_replace works, that would be groovy :)
But beggars cannot be choosers and I would be ecstatic with just the
preg_replace itself!!

View Replies !
Random Word Generation From A Selection Of Words
does anyone have a piece of code, which randomly generates a word? For example, when you click on a link called say...   Random Name, it will come up with a name, either Paul, Luke, John or Terry (but only one of them, so eventually I can have loads so it goes on and on...) Get what i mean?

If you're wondering why I need this, it because I'm making a website where you can choose a type of pet and then click on  'Gimme A Hamster Name' and it will come up with a hamster's name.

View Replies !
How Can I Make Use Of The * Like This '*apple' Where Words Match If They End With The Word?
According to this text from

http://dev.mysql.com/doc/refman/5.0...xt-boolean.html mysql

supports the * like this 'apple*' "Words match if they begin with the word preceding the * operator." But how can I make use of the * like this '*apple' where words match if they end with the word?

View Replies !
Use Ereg To Find Two Different Words In A String?
Can you use ereg to find two different words in a string (I'm trying to look for AND and OR) and then do two more ereg's to look for those same words but seperately.

View Replies !

Copyright © 2005-08 www.BigResource.com, All rights reserved