Difference Between The 2 Statements

R

RN1

Consider the following RegularExpression:

====================
q[^u]
====================

One of the RegEx tutorials I have come across says the following
w.r.t. the above RegEx:

====================
The above RegEx does not mean a 'q' not followed by a 'u'; rather it
means a 'q' followed by a character that is not a 'u'.
====================

Now what's the difference between the 2 statements that I have cited
above?

Thanks,

Ron
 
J

Jesse Houwing

Hello RN1,
Consider the following RegularExpression:

====================
q[^u]
====================
One of the RegEx tutorials I have come across says the following
w.r.t. the above RegEx:

====================
The above RegEx does not mean a 'q' not followed by a 'u'; rather it
means a 'q' followed by a character that is not a 'u'.
====================
Now what's the difference between the 2 statements that I have cited
above?

Thanks,


condider this input:

q

this could be read as a q not followed by a u.

condider

qd

this could be read as a q not followed by a u.

in regex this would be written as:

q(?!u)

The other regex however will never match the first option, because q[^u]
alsways needs to match at least 2 characters, a q and a different character
than u.
 
P

Peter Morris

q followed by anything as long as it is not q == match
q followed by q == no match
 

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

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top