Solved

Problem with regular expression

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
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…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now