473,324 Members | 2,456 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Regualr Expression

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
4 1215
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

23
by: Paul Rubin | last post by:
OK, I want to scan a file for lines matching a certain regexp. I'd like to use an assignment expression, like for line in file: if (g := re.match(pat, line)): croggle(g.group(1)) Since...
70
by: Roy Yao | last post by:
Does it mean "(sizeof(int))* (p)" or "sizeof( (int)(*p) )" ? According to my analysis, operator sizeof, (type) and * have the same precedence, and they combine from right to left. Then this...
22
by: Tony Johansson | last post by:
Hello Experts! I'm reading i a book about C++ and they mention infix with telling what it is. I hope you out there can do so. Many thanks! //Tony
2
by: Mike Turco | last post by:
I like using the expression builder for a lot of different things but it isn't always available when I want to use it, for example in the code window, or in all of the control properties. I am...
14
by: John Temples | last post by:
Given this code: extern volatile unsigned char v; int main(void) { v; return 0; }
2
by: Tom | last post by:
I have a regular expression that replaces a 2,103,518 file with the following but I'm getting a TimeOut in .NET! Can anyone assist? My server is running Windows Server 2000 with all the latest...
28
by: Marc Gravell | last post by:
In Linq, you can apparently get a meaningful body from and expression's .ToString(); random question - does anybody know if linq also includes a parser? It just seemed it might be a handy way to...
18
by: dspfun | last post by:
Hi! The words "expression" and "statement" are often used in C99 and C- textbooks, however, I am not sure of the clear defintion of these words with respect to C. Can somebody provide a sharp...
2
by: sdanda | last post by:
Hai, My string must be 3 characters.First character must be integers in the range 1-9. and second character must be * and third character must be the number with in the range 0 to 9. I wrote this...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.