Regular expressions Question HELP 
Author Message
 Regular expressions Question HELP

I'm trying to use a regular expression to mak sure a string does NOT
match "0000" (four zeros in a row).  This is what I thought would work
- "[^0]{4}" but if a zero is the first charactor it will also fail
(01234 fails).  What is the correct way to check that "0000" was not
matched?

Thanks



Tue, 22 Nov 2005 17:13:41 GMT  
 Regular expressions Question HELP


Quote:
> I'm trying to use a regular expression to mak sure a string does NOT
> match "0000" (four zeros in a row).  This is what I thought would work
> - "[^0]{4}" but if a zero is the first charactor it will also fail
> (01234 fails).  What is the correct way to check that "0000" was not
> matched?

> Thanks

if($foo !~ /0000/) { ... }


Tue, 22 Nov 2005 17:18:18 GMT  
 Regular expressions Question HELP

Quote:

> Subject: Regular expressions Question  HELP

Subject lines are important.  Do not shirk your responsibily.

"Question" is noise in subject lines.  Leave it out.

"HELP" is read as "please ignore".  Leave it out.

"Regular expressions" is a very wide topic.  You need to be  more precise.

If in doubt try this simple test.  Imagine you could have been
bothered to have done a search before you posted.  Next imagine you
found a thread with your subject line.  Would you have been able to
recognise it as the same subject?

Remember, just because you are asking a question, you should not come
here displaying a "take, take, take!" mindset.  As an asker of
questions you can still contribute if you take care with your subject
lines.  Your carefully constucted subject lines will help to lead the
next person to the answer.

Better still, rather than imagining, actually do a search.  If you
don't find the answer then make sure that whatever subject line you
choose would have been found by your search.

For example, this question was posted here in the last month with subject lines
"Negating phrases" and "dont match this pattern".

Theses are not perfect but can you see how much more helpful they are
than "Regular expressions Question  HELP"?

Quote:
> I'm trying to use a regular expression to mak sure a string does NOT
> match "0000" (four zeros in a row).

That is the wrong tool for the job.

The way to negate a condition is to negate the condition.

i.e.

  ! /0000/

Quote:
>  This is what I thought would work
> - "[^0]{4}"

Why would you think that?

  "String does not contain four consecutive '0' characters"

Is nothing like

  "String contains four consecutive non-'0' characters"

Quote:
> What is the correct way to check that "0000" was not matched?

 ! /0000/

For another (INHO, incorrect way) see the other threads to which I
allude.

--
     \\   ( )
  .  _\\__[oo

 .  l___\\
  # ll  l\\
 ###LL  LL\\



Tue, 22 Nov 2005 17:48:23 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. quick regular expression question, please help!

2. Please help in Regular expression question!!

3. Regular Expression Help (Easy Question)

4. regular expression question. pls help

5. Help - Perl regular expression question!

6. Help need with regular expressions and try to find the expression .t

7. Question on regular expressions

8. Regular expression question...

9. Regular Expression newbie question

10. Regular Expression Question...

11. regular expression question

12. newbie regular expression question

 

 
Powered by phpBB® Forum Software