0

In TextPad I am trying to find any line that does not start with a 6 or 7 digit number. So it should find all lines that do not look like:

"123456" or "1234567"

I wrote this expression:

^[^(\d{6,7})]

It is not finding lines that start with only 2 digits like this:

"12 months"

Maybe because the min/max {} expression isn't applying to the negate statement?

Thanks

Sam Brown
  • 3
  • 4
  • It is `^(?!\d{6}).*` – Wiktor Stribiżew Apr 28 '20 at 19:37
  • Perhaps `^(?!\d{6,7}(?!\d)).*` – Cary Swoveland Apr 28 '20 at 19:39
  • Sam, do you wish to match the string `"123456789abc"`. I suspect "yes", for otherwise you would not referred to both "6" and "7" digits; you would have said "6 or more digits" or "6 digits". @WiktorStribiżew, if Sam says "yes", this question is not a dup of the earlier question you referenced in closing this question. – Cary Swoveland Apr 28 '20 at 19:48
  • 1
    The look-ahead in the linked question answered my question. I used ```^(?!\d{6,7})``` and got the results I expected. Thanks all. – Sam Brown Apr 28 '20 at 19:55
  • Sam, please answer my question. – Cary Swoveland Apr 28 '20 at 19:59
  • `^(?!\d{6,7})` is the same as `^(?!\d{6})` and matches `"123456789"`. – Cary Swoveland Apr 28 '20 at 20:12
  • @CarySwoveland It will be still a dupe. [My answer](https://stackoverflow.com/a/37988661/3832970) gives the solution for this, too, see *a string equal to some string (say, not equal to foo)* part. And for this case, `^(?!\d{6,7}$).*`. But for this question, namely, *any line that does not start with*, even the accepted answer is a solution. There are also threads to explain any kind of boundaries like `(?!\d)`, `\b`, `(?!\w)`, `(?!\S)`, etc. We may add this to the current dupe reason. – Wiktor Stribiżew Apr 28 '20 at 20:12
  • @Wiktor, had Sam answered my question "yes", this question would not be a dup of the earlier question you referenced, and readers going to that question would be disappointed to find that is not helpful. You have made the point that regardless which interpretation Sam intended, it is answered by your answer to an earlier question, making it a dup. I agree. I therefore suggest you reference that question as the basis for closing this one as a dup (and leave your last comment). – Cary Swoveland Apr 28 '20 at 20:31
  • @CarySwoveland I referenced exactly that thread. The link always leads to the question, and each question can have lots of answers, and it is not always true that the accepted answer if the best. – Wiktor Stribiżew Apr 29 '20 at 08:00

0 Answers0