RegEx Generator for all languages

A buddy of mine sent me a gem today.  A regular expression generator that is like no other.  So here is how it works:

“This system acts as a regular expression generator. Instead of trying to build the regular expression, you start off with the string that you want to search. You paste this into the site, click submit and the site finds recognisable patterns in your string. You then select the patterns that you are interested in and it writes a fully fledged program that extracts those patterns from that string. You then copy the program into your editor or IDE and play with it to integrate it into your program.”

txt2reg

 

Advertisements
Posted in Tools. Tags: . Leave a Comment »

Regular Expression Helper Class

using System;
using System.Text.RegularExpressions;

namespace RickSchott.Util
{
    ///
    /// Summary description for RegExValidators.
    ///
    public class RegExValidators
    {
        public const string regPhoneNumber = @"^(?:([2-9]d{2}) ?|[2-9]d{2}(?:-?| ?))[2-9]d{2}[- ]?d{4}$";
        public const string regEmail = @"^[w-]+(?:.[w-]+)*@(?:[w-]+.)+[a-zA-Z]{2,7}$";
        public const string regZipCode = @"^(?(^00000(|-0000))|(d{5}(|-d{4})))$";
        public RegExValidators()
        {
            //
            // TODO: Add constructor logic here
            //
        }
        public static bool isValid(string input, string regConst)
        {
            return Regex.Match(input, regConst).Success;
        }
    }
}
Posted in C#. Tags: , . Leave a Comment »