We know that in [a|b|c] the '|' represent 'or', how to present a 'and' condition to match a string? like a&b&c ? regardless of appearing order of a b c in the string.
How could it been done with regexp?
Contain all of the string listed, regardless of display orde
Moderator: General Moderators
Re: Contain all of the string listed, regardless of display orde
Regular expressions are always position based. So if you need to account for all combinations of those three letters you need to be explicit.
Code: Select all
[(abc)(acb)(bac)(bca)...]Re: Contain all of the string listed, regardless of display orde
Thx for your reply, ghurtado.
Re: Contain all of the string listed, regardless of display orde
i'm not very good at regex and there's probably loads of ways to skin this cat ( would be interested to read of others to help my learning of regex) but wouldn't something like
achieve the same and be easier to write
Code: Select all
/[A-Ca-c]{3}/achieve the same and be easier to write
Re: Contain all of the string listed, regardless of display orde
It would not be the same if you need to guarantee that there is at least one of each a, b or c, since "aaa" would match your regexp. At the same time, I don't really know if that was a requirement of the OP, I just kindof assumed.
- prometheuzz
- Forum Regular
- Posts: 779
- Joined: Fri Apr 04, 2008 5:51 am
Re: Contain all of the string listed, regardless of display orde
Note that inside the square brackets (character class or character set), the pipe symbol is not a logical OR, but matches just the character '|'.coldwinds wrote:We know that in [a|b|c] the '|' represent 'or', how to present a 'and' condition to match a string? like a&b&c ? regardless of appearing order of a b c in the string.
How could it been done with regexp?
Re: Contain all of the string listed, regardless of display orde
I think this is a job for strpos() rather than a regular expression.
Re: Contain all of the string listed, regardless of display orde
yeah your right ghurtado.
I get it now
I get it now