Cyberflow Posted November 22, 2004 Posted November 22, 2004 Hi, I've tryed out several ways with regular expressions, but couldn't make the good one ... Here is piece of my 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 : Delete 171 And usually it always have : Delete "Id number up to 999999" So what is wrong with this regular expression ? : ^(Delete{1})([:space:]{1})([:digit:]{1,6})(.*) Quote
vozeldr Posted November 24, 2004 Posted November 24, 2004 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 $. Quote
Cyberflow Posted November 24, 2004 Author Posted November 24, 2004 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. Quote
vozeldr Posted November 25, 2004 Posted November 25, 2004 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. Quote
Cyberflow Posted November 25, 2004 Author Posted November 25, 2004 There is one of those little pocket guides by Oreily that is dedicated to regular expressions and it has platform specific information for .NET' date=' 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.[/quote'] 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. Quote
*Gurus* Derek Stone Posted November 25, 2004 *Gurus* Posted November 25, 2004 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. Quote Posting Guidelines
Cyberflow Posted November 25, 2004 Author Posted November 25, 2004 Cyberflow: These are .NET forums' date=' 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.[/quote'] 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. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.