Solved

Problem with regular expression

Posted on 2004-03-29
5
182 Views
Last Modified: 2006-11-17
hi,

i have problem with regular expression in php..
suppose i want to create a search facility..
when user entered, for example : "artist+korean+pop",
it will begin a search using these 3 words as a keywords.

My problem is.. i don't know how to form a regular expression that match these criterias...
For that example, i will form "(artist|korean|pop)+(artist|korean|pop)+(artist|korean|pop)+".

Very silly heh? if there're 10keywords, it will grow too...
could somebody help me,plz...
0
Comment
Question by:winart
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 12

Expert Comment

by:venkateshwarr
ID: 10706380

Why dont you match inidividual strings in a loop

$strs = split(" ", "artist korean php");

for($i=0;$i<sizeof($strs);$i++)
{
       //match pattern with $strs[$i];
}

venkat.
0
 

Author Comment

by:winart
ID: 10709883
that's not what i want..

the pattern "artist+korean+pop" means :
1. these string : "artist korean pop" is match.
2. string : "korean artist pop" is match too!
3. string : "pop artist korean" is match too!

i bet your solution just worked for the 1st possibilities,right?

thx anyway..
0
 
LVL 12

Accepted Solution

by:
venkateshwarr earned 300 total points
ID: 10710958
The above loop checks if each individual pattern keyword is present in the string.....

So what you have to do is "artist+korean+pop"
while searching a string if you find a keyword "korean" the check the next two keywords in the string for "artist" and "pop"
similarly if you find "pop" check the next two keywords for "artist" and "korean"

Of course you have to automate this for any number of keywords...

venkat.
0
 

Author Comment

by:winart
ID: 10712771
that's my problem!

i think it is very silly to create a looping for thing like that..
cause there'll be too many possibilities..
there a simpler approach, right?
by using regular expression...

thx,
0
 

Author Comment

by:winart
ID: 10720813
sorry,

i've found the answer..
by using RE.
anyway, thx for helping me..

win
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question