-2

I have the following string. Each number is separated by a tab

35  64  -33 -39 37  49  41  34

I am trying to find a suitable regex expression to match that string so I can use it in my C# program. So far I have tried a few online tools but those tools could not generate it.

What I am trying to achieve is to match

56  110 -47 -58 57  73  59  47

but not

56  110 -47 -58 a   73  59  47

EDIT: the regex must match any number. Those are just a few examples from my file. The numbers can be both positive, negative and 0

I am using the regex to validate if a text file is consited only of lines with the above structure (letters only and tabs as separation).

Konamiman
  • 49,681
  • 17
  • 108
  • 138
J Doe
  • 11
  • 1
  • 4
  • possible dupe: https://stackoverflow.com/questions/273141/regex-for-numbers-only?rq=1 – sniperd Jun 12 '18 at 14:13
  • Do you want it to match the numbers in the last example, and just skip the `a`? – AndreasHassing Jun 12 '18 at 14:13
  • @AndreasBjørnHassingNielsen I do not want to match the line if it has anything but number. It must match the tabs and from 1 to 8 numbers. Also added an edit to my question. – J Doe Jun 12 '18 at 14:15
  • So it can only be numbers, you want a regex to find letters? This is a pretty basic usage of regex. Can you show us what you've tried so far? –  Jun 12 '18 at 14:15
  • Perfect opportunity to advertise this awesome Regex gem: https://regex101.com/ – AndreasHassing Jun 12 '18 at 14:19
  • 1
    For c#, try [regexstorm](http://regexstorm.net/tester), regex101 does not support C# flavored regex. – Nilay Vishwakarma Jun 12 '18 at 14:21
  • 1
    @NilayVishwakarma Regex101 is kilometers ahead with regards to user experience, and in most cases the Regex does work in C#. If you need to do something out of the general regex queries (lookahead/behinds and advanced/named grouping), then sure, regexstorm makes more sense. – AndreasHassing Jun 12 '18 at 14:25

1 Answers1

0

^(-?((\d*\.?\d+)|(\d+\.?\d*))\t)*(-?((\d*\.?\d+)|(\d+\.?\d*)))$ If you want to grab the whole string if and only if all the values within are tabbed numbers

-?((\d*\.?\d+)|(\d+\.?\d*)) if you want to grab each individual number in the string

N.D.C.
  • 1,601
  • 10
  • 13