-2

I'm trying to match anything that's NOT:

  • either just digits (ex. 0024753766)
  • or just digits preceded by a '+' (ex. +347868646)

In other words, any non-digit character that's not an initial +.

I've done some research and a lot of trial and error and I'm going crazy cause it sounds so simple and yet I can't figure it out.

Closest help I found was Regex ignoring first character if it's a $ but I'm too new to regex to be able to fine tune it to my specific needs.

That's the last bit of code I need to complete my project and I'm stuck as hell.

bobble bubble
  • 16,888
  • 3
  • 27
  • 46
Paul
  • 9
  • 1
  • What about a single `+`, should it be matched? – knittl Aug 29 '23 at 16:35
  • `^(?!\+?\d+$).*` ? – Bohemian Aug 29 '23 at 16:37
  • @Bohemian Yessss!!! Looks perfect. Thank you. :) – Paul Aug 29 '23 at 16:53
  • @knittl Yes it works as well I guess, I won't be too picky for my project at this stage. Good point though, hadn't thought of that case, so thanks for that. :) – Paul Aug 29 '23 at 16:57
  • Welcome! How about [this demo?](https://regex101.com/r/xK1waq/1) It will be easier if you provide some samples with input and desired outcome. Also mention the environment where you are doing this. – bobble bubble Aug 29 '23 at 19:10
  • If you're doing this in a programming language (rather than a tool like Notepad++), it would probably be simpler and faster to match what you *don't* want with `^\+?\d+$` and negate it in your code. – CAustin Aug 29 '23 at 22:56

0 Answers0