pcre.c : And Operator

S

sgane2001

Hi,
I'm using pcre.c to provide regex support for my application
software. I want to know how to do 'AND' operation in this. I didn't
got any useful info from the net.

Is this operator available or not? If not how could we do this
operation? Any stuffed replies or redirection will be appreciated.

Thanks,
Ganesh
 
G

Gregory Toomey

Hi,
I'm using pcre.c to provide regex support for my application
software. I want to know how to do 'AND' operation in this. I didn't
got any useful info from the net.

Is this operator available or not? If not how could we do this
operation? Any stuffed replies or redirection will be appreciated.

Thanks,
Ganesh

What on earth is an AND operator in a regular expression?

gtoomey
 
S

sgane2001

What on earth is an AND operator in a regular expression?

If you have an OR ( | ) operator, where is the ( & )
 
S

sgane2001

would need to ax and bx and cx simultaneously which is
"match ax bx cx". I want to match ax,bx,cx in the string. How can I do
this then. If one of these there is not there then it should print
false.

-Ganesh
 
J

Joona I Palaste

(e-mail address removed) scribbled the following:
"match ax bx cx". I want to match ax,bx,cx in the string. How can I do
this then. If one of these there is not there then it should print
false.

What do you mean by "match ax bx cx" or "match ax,bx,cx"? What
*specific* criterion should the string match?
Do you mean any string that includes *all* of "ax", "bx" and "cx", not
just any one of them? If so, then one very awkward way would be
something like:
(*ax*bx*cx*)|(*ax*cx*bx*)|(*bx*ax*cx*)|(*bx*cx*ax*)|(*cx*ax*bx*)|
(*cx*bx*ax*)
I think there's a shorter way but I can't come up with one now. If
that's not what you want, then what is?
 
L

Lawrence Kirby

"match ax bx cx". I want to match ax,bx,cx in the string. How can I do
this then. If one of these there is not there then it should print
false.

Regular expressions can't do that directly. The simplest way is probaby to
perform 3 separate searches.

Lawrence
 
T

Tim Rentsch

some incidental interloper responded to someone who wrote:

[Regarding the '&' operator in regular expressions...]

Forgive me for not responding to the orignal article,
my news server has lost track of it.

The '&' operator isn't meaningless, it means language
intersection. (At least, that's a reasonable guess.)

So, the expression

(a|b|c)&(c|d|e)

would be the same as the expression

c

or, for another example

[a-n]&[i-z]

would be the same as the expression

[i-n]

In these examples only letters are literal characters,
others are all meta-characters.

Can interested parties take this discussion to a newsgroup
more appropriate than comp.lang.c? Thank you.
 
S

sgane2001

Factor it. [a|b|c]x

What I want is, match all the patterns in the given string. I knew that
we can match all the patterns if they are given in order of occurance.
But how to do that in case of un-ordered patterns.

Ex: String ---> "Match the occurances of "match", "this" in this
string"

String =~ /'this' & 'match'/ . How can I do this?
 
M

Michael Mair

CBFalconer said:
Lawrence said:
On Thu, 17 Feb 2005 01:53:22 -0800, sgane2001 wrote:

... snip ...
Regular expressions can't do that directly. The simplest way is
probaby to perform 3 separate searches.


Factor it. [a|b|c]x

You seem to have misunderstood the problem:
ax _and_ bx _and_ cx have to be in the string but in
arbitrary order. I think that short of writing out
(ax.*bx.*cx) | (ax.*cx.*bx) | .....
which gets increasingly long (n! for n different substrings to match)
you really should just run through the subexpressions to be tested
and find whether each matches individually.
Consistency checks beforehand left as exercise :)


Cheers
Michael
 
C

Chris Croughton

Factor it. [a|b|c]x

What I want is, match all the patterns in the given string. I knew that
we can match all the patterns if they are given in order of occurance.
But how to do that in case of un-ordered patterns.

Ex: String ---> "Match the occurances of "match", "this" in this
string"

String =~ /'this' & 'match'/ . How can I do this?

You can't using regular expressions, except by matching each of the
strings separately:

/this/ && /match/

As you have been told, this is off-topic for comp.lang.c, ask in a group
which is about regular expression, or since pcre.c is for Perl type REs
ask in a Perl group. Or since you have the source of pcre.c, and it is
Free Software, you can modify it yourself. Or even email the author...

Chris C
 
L

Lawrence Kirby

Factor it. [a|b|c]x

What I want is, match all the patterns in the given string. I knew that
we can match all the patterns if they are given in order of occurance.
But how to do that in case of un-ordered patterns.

Ex: String ---> "Match the occurances of "match", "this" in this
string"

String =~ /'this' & 'match'/ . How can I do this?

Methods have already been covered. Regular expressions aren't really a
good way to solve this. Also consider if the strings you want to consider
are, say "match" and "matchstick", would the string "matchstick" match
both or do the pattern strings have to exist separately?

This isn't a discussion of the C programming language, maybe a newsgroup
such as comp.programming would be more appropriate.

Lawrence
 
S

sgane2001

Chris said:
As you have been told, this is off-topic for comp.lang.c, ask in a group
which is about regular expression, or since pcre.c is for Perl type REs
ask in a Perl group. Or since you have the source of pcre.c, and it is
Free Software, you can modify it yourself. Or even email the author...

Chris C

It's not me who diverted the topic, I just wanted to know whether there
is an operator for performing '&' Operation in that 'C' Free Ware and
if so how to use that. Refer Subject of this message. BTW thanks for
your re-direction.

-Ganesh
 
S

sgane2001

Chris said:
As you have been told, this is off-topic for comp.lang.c, ask in a group
which is about regular expression, or since pcre.c is for Perl type REs
ask in a Perl group. Or since you have the source of pcre.c, and it is
Free Software, you can modify it yourself. Or even email the author...

Chris C

It's not me who diverted the topic, I just wanted to know whether there
is an operator for performing '&' Operation in that 'C' Free Ware and
if so how to use that. Refer Subject of this message. BTW thanks for
your re-direction.

-Ganesh
 
G

Gregory Toomey

Michael said:
CBFalconer said:
Lawrence said:
On Thu, 17 Feb 2005 01:53:22 -0800, sgane2001 wrote:

... snip ...
"match ax bx cx". I want to match ax,bx,cx in the string. How
can I do this then. If one of these there is not there then it
should print false.

Regular expressions can't do that directly. The simplest way is
probaby to perform 3 separate searches.


Factor it. [a|b|c]x

You seem to have misunderstood the problem:
ax _and_ bx _and_ cx have to be in the string but in
arbitrary order. I think that short of writing out
(ax.*bx.*cx) | (ax.*cx.*bx) | .....
which gets increasingly long (n! for n different substrings to match)
you really should just run through the subexpressions to be tested
and find whether each matches individually.
Consistency checks beforehand left as exercise :)


Cheers
Michael

I think you're right. The OP is asking to match a permutation.

gtoomey
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top