#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2008
    Posts
    71
    Rep Power
    6

    "between 0 and X" not working as expected?


    Hello I copied a snippet of JavaScript from a blog, but unfortunately it included all the fancy line numbers and indentation used on the webpage.

    I wanted to quickly strip all those line numbers and extra line returns by making a simple regular expression to find & replace:

    (\d{0,2}\s{0,2})

    won't match anything in RegExr (google "RegExr Gskinner"), and in sublime text 2 it is matching as expected....

    Why is this?
  2. #2
  3. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,911
    Rep Power
    1045
    Hi,

    I'm pretty sure this pattern is not what you want. It matches any sequence of digits or spaces anywhere in the whole input. If you run it on a piece of code, you'll end up with a mess.

    The first thing you'll need is an anchor to only match digits at the beginning of a line:

    Code:
    ^\d{0,2}\s{0,2}
    The regex may need further fine-tuning, but I can't tell without seeing the concrete input.

    I have no idea why you get no matches in RegExr. But why does that matter, anyway?
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2012
    Posts
    776
    Rep Power
    495
    Or get an text editor that can work in column mode to remove the first characters on every line.

IMN logo majestic logo threadwatch logo seochat tools logo