Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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})(.*)

Posted

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 $.

Posted
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.

Posted
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.
Posted
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.

Posted
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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...