Advertisement
Aborigenius

MatchNumbers

Aug 25th, 2017
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.59 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6. using System.Threading.Tasks;
  7.  
  8. namespace MatchNumbers
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             var pattern = @"(^|(?<=\s))-?\d+(\.\d+)?($|(?=\s))";
  15.  
  16.             string numbersInput = Console.ReadLine();
  17.  
  18.             MatchCollection number = Regex.Matches(numbersInput, pattern);
  19.  
  20.             foreach (var num in number)
  21.             {
  22.                 Console.Write($"{num} ");
  23.             }
  24.         }
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement