How to check if a string contain a substring using Regex() in C#

3 Answers

0 votes
using System;
using System.Text.RegularExpressions;

namespace ConsoleApplication_C_Sharp
{
    static class Program
    {
        static void Main(string[] args)
        {
            Regex regex = new Regex("prog.*");

            Console.WriteLine(regex.IsMatch("c# programming")); 
        }
    }
}


/*
run:
  
True
   
*/

 



answered Feb 7, 2017 by avibootz
0 votes
using System;
using System.Text.RegularExpressions;

namespace ConsoleApplication_C_Sharp
{
    static class Program
    {
        static void Main(string[] args)
        {
            Regex  regex = new Regex("prog*");

            Console.WriteLine(regex.IsMatch("pr"));
            Console.WriteLine(regex.IsMatch("pro"));
            Console.WriteLine(regex.IsMatch("programming")); 
            Console.WriteLine(regex.IsMatch("prop")); 
        }
    }
}


/*
run:
  
False
True
True
True
   
*/

 



answered Feb 7, 2017 by avibootz
0 votes
using System;
using System.Text.RegularExpressions;

namespace ConsoleApplication_C_Sharp
{
    static class Program
    {
        static void Main(string[] args)
        {
            Regex regex = new Regex("Fibonacci(n)*$");

            Console.WriteLine(regex.IsMatch("Fibonaccin")); 
            Console.WriteLine(regex.IsMatch("Fibonacci")); 
            Console.WriteLine(regex.IsMatch("Fib"));
            Console.WriteLine(regex.IsMatch("Fibonacci(")); 
        }
    }
}


/*
run:
  
True
True
False
False
   
*/

 



answered Feb 7, 2017 by avibootz

Related questions

...