?
Solved

Problem with regular expression

Posted on 2004-03-29
5
Medium Priority
?
187 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
  • 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 600 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses
Course of the Month13 days, 12 hours left to enroll

757 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