Help to 'eregi' with a regular expressions

Cyberflow

Member
Joined
Nov 19, 2004
Messages
5
Hi,

Ive tryed out several ways with regular expressions, but couldnt 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 dont 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 dont 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.

Doesnt seem to work, but i dont understand, the pattern is well written ! ...

Its 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... Its 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... Its a pretty good little book to keep in the desk drawer for easy reference. Costs like $9.99 or something.
Ive printed like for 10 different references documents and tutorials from the net ... I dont think im going to buy it ...

There is one book from Oreillys 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 youre 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 youre 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.

Anyways ... i understand, sorry.
 
Back
Top