By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,664 Members | 1,669 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,664 IT Pros & Developers. It's quick & easy.

Regualr Expression

P: n/a
Hi,

Just wondering if anybody can help me out with a regular expression.

What i need to do is match a sting of 5+ words, with the words in any
order. The below will perform the operation -

^(word1|word2|word3|word4|word5)+$

Although this works, this will also match alot of stuff that contains any
of those words, not contains all the words, which is what i need.

Any info greatly appreciated, i can ellaborate on the problem if needed,

Cheers

Will

Feb 23 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
On Feb 23, 11:59 am, "willl69" <will...@gmail.comwrote:
Hi,

Just wondering if anybody can help me out with a regular expression.

What i need to do is match a sting of 5+ words, with the words in any
order. The below will perform the operation -

^(word1|word2|word3|word4|word5)+$

Although this works, this will also match alot of stuff that contains any
of those words, not contains all the words, which is what i need.

Any info greatly appreciated, i can ellaborate on the problem if needed,

Cheers

Will
^(word1|word2|word3|word4|word5){5}$

Will require 5 words, but this will still let your user enter the same
word 5 times. Do you need an instance of all 5 words?

Feb 23 '07 #2

P: n/a
willl69 schreef:
Just wondering if anybody can help me out with a regular expression.

What i need to do is match a sting of 5+ words, with the words in any
order. The below will perform the operation -

^(word1|word2|word3|word4|word5)+$

Although this works, this will also match alot of stuff that contains any
of those words, not contains all the words, which is what i need.

Any info greatly appreciated, i can ellaborate on the problem if needed,
The following will report invalid words, but won't check that all words
are present:

$sentence = 'word1word2';

if (count(preg_split('/(word1|word2|word3|word4|word5)/',
$sentence,
-1,
PREG_SPLIT_NO_EMPTY))) {
print 'unknown words found';
}
JW
Feb 23 '07 #3

P: n/a
That would work, however i need it in the one regular expression if
possible as it needs to port across platforms (ie php, mysql, perl). Its
highly possible that it is completely impossible, just trying to save my
self extra coding

Feb 23 '07 #4

P: n/a
Rik
On Fri, 23 Feb 2007 13:48:35 +0100, willl69 <wi*****@gmail.comwrote:
That would work, however i need it in the one regular expression if
possible as it needs to port across platforms (ie php, mysql, perl). Its
highly possible that it is completely impossible, just trying to save my
self extra coding
The only way I see it done in a regular expressions is a hidous nested
beast of a regex, which details all of the possibilities. Regex is
certainly no way to go here.
--
Rik Wasmus
Feb 23 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.