Militsa

09. Match Numbers

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