Solved

Problem with regular expression

Posted on 2004-03-29
5
180 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 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying 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

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

840 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