C # uses regular expression to match string validation URL example

Source: Internet
Author: User
Tags url example
In the System.Text.RegularExpression namespace, there is a regular expression method.

Using System.Collections.Generic;
Using System.Text;
Using System.Text.RegularExpressions;

Namespace Regexdemo
{
Class Program
{
static void Main (string[] args)
{
Regex regex = new Regex ("China", regexoptions.ignorecase);
Use the match method.
String Source = "Mother,my mother is china!";
Match m = regex. Match (source);
if (m.success)
{
Console.WriteLine ("Find first match");
}
Console.WriteLine (New String ('-', 9));
The following example shows a match using the matches method
MatchCollection Matches=regex. Matches (source);
foreach (Match s in matches)
{
if (s.success)
Console.WriteLine ("Found a Match");
}
Console.ReadLine ();
}
}
}
[/code]

Using system.collections.generic;using system.text;using system.text.regularexpressions;namespace URLRegex{    Class program    {        static void Main (string[] args)        {            string Pattern = @ "^ (http|https|ftp) \://[a-za-z0-9\ -\.] +\. [A-za-z] {2,3} (: [a-za-z0-9]*)?/? ([a-za-z0-9\-\._\?\,\ '/\\\+&$%\$#\=~]) *$ ";            Regex r = new Regex (Pattern);            String Source = "Http://www.jb51.net";            Match m = r.match (source);            if (m.success)            {                Console.WriteLine ("URL verified successfully!");            }            else            {                Console.WriteLine ("URL validation failed!");            }            Console.ReadLine ();}}}    


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.