Help to 'eregi' with a regular expressions

Cyberflow

Newcomer
Joined
Nov 19, 2004
Messages
5
Hi,

I've tryed out several ways with regular expressions, but couldn't make the good one ...

Here is piece of my code

Code:
[PHP]if(eregi("^(Delete{1})"
."([:space:]{1})"
."([:digit:]{1,6})(.*)",$rs[4], $resb))[/PHP]

So what i want it to do is to check into the variable $rs[4] if it has this :

Code:
Delete 171

And usually it always have : Delete "Id number up to 999999"

So what is wrong with this regular expression ? :

Code:
^(Delete{1})([:space:]{1})([:digit:]{1,6})(.*)
 
For one, put the conditionals outside of the grouping. Second, you don't need to group single characters because, well...they are single characters.

Regex rx = new Regex("^(Delete){1}\s{1}\d{1,6}$");
bool valid = rx.IsMatch("Delete 171");


valid will be true.

If you want it to be valid to have additional data after Delete 171, just remove the $.
 
vozeldr said:
For one, put the conditionals outside of the grouping. Second, you don't need to group single characters because, well...they are single characters.

Regex rx = new Regex("^(Delete){1}\s{1}\d{1,6}$");
bool valid = rx.IsMatch("Delete 171");


valid will be true.

If you want it to be valid to have additional data after Delete 171, just remove the $.
I am working with php.

Doesn't seem to work, but i don't understand, the pattern is well written ! ...

It's kind of confusing all this.
 
There is one of those little pocket guides by Oreily that is dedicated to regular expressions and it has platform specific information for .NET, PHP, JavaScript, etc... It's a pretty good little book to keep in the desk drawer for easy reference. Costs like $9.99 or something.
 
vozeldr said:
There is one of those little pocket guides by Oreily that is dedicated to regular expressions and it has platform specific information for .NET, PHP, JavaScript, etc... It's a pretty good little book to keep in the desk drawer for easy reference. Costs like $9.99 or something.
I've printed like for 10 different references documents and tutorials from the net ... I don't think i'm going to buy it ...

There is one book from Oreilly's it is Mastering regular expression 2nd edition it is about 65$ CAD ....

But never heard of the pocket edition.
 
Cyberflow: These are .NET forums, hence the name Xtreme .NET Talk. If you're having problems with PHP you might be best to consult with a more applicable source of information.
 
Derek Stone said:
Cyberflow: These are .NET forums, hence the name Xtreme .NET Talk. If you're having problems with PHP you might be best to consult with a more applicable source of information.
Oh i am sorry, i was searching for a "Forum Regular Expressions" with google, and here seemed to be the biggest one ...

It is very hard to have help with regular expressions.

Anyway's ... i understand, sorry.
 
Back
Top