Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Dec 2004
    Location
    Jamaica
    Posts
    592
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Help with regex plz... :(

    I have the following regex that will match any number from 1-999. Here it is:
    "([1-9]\d{0,2})(?!-| -|\d-|\d -)"
    I need to add to the front.. there should be NO greater than or less than signs or dashes at the start of the string. The only thing allowed at the start of the string is a space or it can be the first character in the string. Please help.
    The second submatch simply looks ahead to make sure that no dashes are found trailing after the match.
    I'm gonna find a way to download the internet if its the last thing I do...
    Prepare to bow down to me (or my grave) and call me almighty when the algorithm is finished

  • #2
    Senior Coder
    Join Date
    Dec 2002
    Location
    Arlington, Texas USA
    Posts
    1,072
    Thanks
    4
    Thanked 8 Times in 8 Posts
    using this at the beginning of your regex ^\s? will allow a space at the beginning of the string

  • #3
    Regular Coder
    Join Date
    Dec 2004
    Location
    Jamaica
    Posts
    592
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by miranda
    using this at the beginning of your regex ^\s? will allow a space at the beginning of the string
    I see that... but the thing is.. the number can appear anywhere in the string. Cannot use ^ right there So its like, the rule that I want is... There should not be either of these to the right or left of the number... <,>,- none.. space is permitted but not any of those characters...
    I'm gonna find a way to download the internet if its the last thing I do...
    Prepare to bow down to me (or my grave) and call me almighty when the algorithm is finished


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •