-1

I am looking for the regEx solution that matches the format of:

number whitespace number whitespace number i.e. 0 2 0 2 2 or 0 10 0 10 4 etc etc

The string can be infinite in length and therefore the expression of the regEx needs to match this however following the same format.

skuntsel
  • 11,346
  • 11
  • 41
  • 64
Charabon
  • 657
  • 1
  • 9
  • 21
  • 2
    Not quite as basic as you'd think to do it right :p `^\d+(?>\s+\d+)*$` should do the trick. Are you saying this is basic? – Niet the Dark Absol May 11 '13 at 20:06
  • 4
    @Kolink: Yes it is. Just some [repetitions](http://www.regular-expressions.info/repeat.html), two [character classes](http://www.regular-expressions.info/charclass.html), and [grouping](http://www.regular-expressions.info/brackets.html) :-) – Bergi May 11 '13 at 20:08
  • 1
    I have tried a number of solutions that i have found online but no luck. i havent used regex for a while so still trying to get my head around it – Charabon May 11 '13 at 20:08
  • Sorry, had to edit. Needed a once-only subpattern in there. – Niet the Dark Absol May 11 '13 at 20:08
  • 1
    @user2373636, Rather than providing the answer for you, it'd be ideal to display the different regular expressions you had attempted which was unsuccessful. This way, we could see where your problem areas are and help to correct and clear any confusion. – Anthony Forloney May 11 '13 at 20:10
  • @Kolink Sadly enough JS regex flavor doesn't support lookaround assertions – HamZa May 11 '13 at 20:14
  • @HamZaDzCyberDeV D'oh, I thought this was PHP XD And now I can't edit it back. Damn. – Niet the Dark Absol May 11 '13 at 20:16
  • 1
    @Kolink hahaha no problem, removing `?>` should make it work `^\d+(\s+\d+)*$` – HamZa May 11 '13 at 20:18
  • 2
    @HamZaDzCyberDeV: Actually it was an ["independent matching group"](http://stackoverflow.com/q/50524/1048572) (to prevent backtracking), not some kind of lookaround (and js supports lookahead, btw). The `(?:` Kolink originally had was perfectly fine… – Bergi May 11 '13 at 20:22
  • @Bergi Ah right, I forget that JS doesn't support lookbehind :p – HamZa May 11 '13 at 20:30
  • 1
    @HamZaDzCyberDeV: It is not look-behind. It is non-backtracking group/atomic group, which means that it prevents backtracking. JS regex doesn't have support for this, though. – nhahtdh May 11 '13 at 20:35
  • @Allendar He doesn't want to split he just want to match the pattern `Number(SpaceNumber)*`. – HamZa May 11 '13 at 20:38

1 Answers1

1

/^\d+(\s\d+)*$/ will match number whitespace number whitespace ... number (only one white space)

/^\d+( \d+)*$/ will match with single space only in between.

These will not match trailing spaces

georg
  • 195,833
  • 46
  • 263
  • 351
user568109
  • 43,824
  • 15
  • 87
  • 118