Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Hierarchical SQL Select
Message
De
08/09/2009 03:16:38
 
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
01422513
Message ID:
01423032
Vues:
69
>>>>In the last example it only matches
>>>>
http://msdn.microsoft.com/en-us/library/
>>>
>>>I'll re-write the test program, for now this
>>>
>>>http://msdn.microsoft.com/en-us/library/aa172799(SQL.80.aspx - works as a valid HTML
>>
>>Why shouldn't it - Who says the parentheses must match ?
>>
>
>Nobody said - I guess that's OK to have mismatched parentheses. I haven't tested if we can have more than 2 of them. UPDATE. Yes, it allows many of them.
>
>Ok, good luck - it's late for me now.


I'll leave it up to you to test it and adjust it
(\b(((((https?)|(ftps?))://|www\.))(((((\d)|(\d{2})|(([01](\d{2}))|(2[0-4](\d))|(25[0-5])))\.){3}((\d)|(\d{2})|(([01](\d{2}))|(2[0-4](\d))|(25[0-5]))))|(((([\w-_]|((%%)|(%[0-9A-Z]{2})))*([a-zA-Z])([\w-_]|((%%)|(%[0-9A-Z]{2})))*)\.)+(([\w-_]|((%%)|(%[0-9A-Z]{2})))*([a-zA-Z])([\w-_]|((%%)|(%[0-9A-Z]{2})))*)))/?)(((((((((%%)|(%[0-9A-Z]{2}))|[^ ()#?^&`{}|\[\]\x22<>\\])|([()]))}\.)+/)*)?((((((%%)|(%[0-9A-Z]{2}))|[^ ()#?^&`{}|\[\]\x22<>\\])|([()]))+\.)*((((%%)|(%[0-9A-Z]{2}))|[^ ()#?^&`{}|\[\]\x22<>\\]))+))?((([?#][^?# ]+)*)?))\b)
Test and pattern builder program - you'll need the RegEx pattern builder download#37200 and topological sort download#37199
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Text.RegularExpressions;
using System.IO;

using GregoryAdam.Base.Text.RegEx;

namespace BaseTest
{
	public class UrlTest
	{
		static void Main()
		{
			string pattern = RegexPatternBuilder.Construct(Definitions, "<url>");
			Console.WriteLine(pattern);
			
			foreach ( string s in TestCases )
			{
				Console.WriteLine("{0}", s);
				var matches = Regex.Matches(s, pattern, RegexOptions.Multiline);

				foreach( var match in matches)
					Console.WriteLine("found «{0}»", match);

			}
			Console.ReadLine();



		}
		static string Definitions = @"
<url>			\b<server>(<segment>?(<query>?))\b

<server>			<serverIntro><serverBody>/?
<serverIntro>		(((https?)|(ftps?))://|www\.)
<serverBody>		<ip>|<serverWords>
<ip>				(<ipPart>\.){3}<ipPart>
<ipPart>			<ip1>|<ip2>|<ip3>
<ip1>				\d
<ip2>				\d{2}
<ip3>				([01]<ip2>)|(2[0-4]<ip1>)|(25[0-5])
<serverWords>		(<serverWord>\.)+<serverWord>
<serverWord>		<serverChar>*<alphaChar><serverChar>*
<serverChar>		[\w-_]|<CharEscaped>
<alphaChar>			[a-zA-Z]


* 
<segment>			<segmentBody>?<segmentTail>
<segmentBody>		((<segmentChar>}\.)+/)*
<segmentTail>		(<segmentChar>+\.)*(<segmentCharNoParens>)+

<segmentCharNoParens>	<CharEscaped>|[^ ()#?^&`{}|\[\]\x22<>\\]
<CharEscaped>		(%%)|(%[0-9A-Z]{2})
<segmentChar>		<segmentCharNoParens>|<parens>

<parens>			[()]
<query>				([?#][^?# ]+)*
";
		static string[] TestCases = 
		{	@"http://msdn.microsoft.com/en-us/library/", 
			@"http://msdn.microsoft.com/en-us/library/aa172799SQL.80.aspx",
			@"(http://msdn.microsoft.com/en-us/library/aa172799SQL.80.aspx)",
			@" www.msdn.microsoft.com/en-us/library/aa139615.aspx ",
			@"http://msdn.microsoft.com/en-us/library/ aa172799SQL.80.a",
			@" (http://msdn.microsoft.com/en-us/library/aa172799(SQL.80).aspx) ",
			@"http://microsoft.com/test.asp?url=/example/abc.asp?frame=true#fragment   ",
			@"http://192.168.10.254/test.asp?url=/example/abc.asp?frame=true#fragment   ",
			@"wwww.192.168.10.254/test.asp?url=/example/abc.asp?frame=true#fragment   ",
			@"www.microsoft.com/test.asp?url=/example/abc.asp?frame=true#fragment   ",
		};
	}

}
Gregory
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform