x Did you like it? Well, then please consider making a donation :)

Simple example - non capturing group

If I apply the regex below over it: (http|ftp)://([^/\r\n]+)(/[^\r\n]*)? I would get the following result: Match "http://stackoverflow.com/" Group 1: "http" Group 2: "stackoverflow.com" Group 3: "/" But I don't care about the protocol - I just want the host and path of the URL. So, I change the regex to include the non-capturing group (?:): (?:http|ftp)://([^/\r\n]+)(/[^\r\n]*)? Now, my result looks like this: Match "http://stackoverflow.com/" Group 1: "stackoverflow.com" Group 2: "/"

Tags: #address, #example, #group, #non capturing, #sample, #simple, #uri, #url, #web. Views: 4294. stackoverflow, 7/12/2015
Link 1: http://www.systemtextregularexpressions.com/m8/simple-example-non-capturing-group
Link 2: http://www.systemtextregularexpressions.com/m8 (short)

Length: 0b, Line: 1, Cursor: 0

RegexOptions

IsMatch=true


#ValueIndexLengthGroupsCaptures
0http://stackoverflow.com/025Skip Navigation Links.
Expand Groups [3]Groups [3]
Skip Navigation Links.
Expand Captures [1]Captures [1]
1http://stackoverflow.com/questions/tagged/csharp2648Skip Navigation Links.
Expand Groups [3]Groups [3]
Skip Navigation Links.
Expand Captures [1]Captures [1]
2http://stackoverflow.com/questions/tagged/.net7546Skip Navigation Links.
Expand Groups [3]Groups [3]
Skip Navigation Links.
Expand Captures [1]Captures [1]
3http://stackoverflow.com/questions/tagged/regex12247Skip Navigation Links.
Expand Groups [3]Groups [3]
Skip Navigation Links.
Expand Captures [1]Captures [1]
Count: 4, Time: 00:00:00

Share (without adding to database):

Source code

0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
//.NET Regex.Match Online Tester: www.systemtextregularexpressions.com

//Namespace
using System.Text.RegularExpressions;

//Regex Pattern
string pattern = @"(?:http|ftp)://([^/\r\n]+)(/[^\r\n]*)?";

//Regex example #1
Regex r = new Regex(@"(?:http|ftp)://([^/\r\n]+)(/[^\r\n]*)?");
Match m1 = r.Match("input text");
MatchCollection mc1 = r.Matches("input text");

//Regex example #2
Match m2 = Regex.Match("input text", @"(?:http|ftp)://([^/\r\n]+)(/[^\r\n]*)?");
MatchCollection mc2 = Regex.Matches("input text", @"(?:http|ftp)://([^/\r\n]+)(/[^\r\n]*)?");
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
'.NET Regex.Match Online Tester: www.systemtextregularexpressions.com

'Namespace
Imports System.Text.RegularExpressions

'Regex Pattern
Dim pattern As String = "(?:http|ftp)://([^/\r\n]+)(/[^\r\n]*)?"

'Regex example #1
Dim r As Regex = New Regex("(?:http|ftp)://([^/\r\n]+)(/[^\r\n]*)?")
Dim m1 As Match = r.Match("input text")
Dim mc As MatchCollection = r.Matches("input text")

'Regex example #2
Dim m2 As Match = Regex.Match("input text", "(?:http|ftp)://([^/\r\n]+)(/[^\r\n]*)?")
Dim mc2 As MatchCollection = Regex.Matches("input text", "(?:http|ftp)://([^/\r\n]+)(/[^\r\n]*)?")

Home     Match     Replace     Split     Help     Library     Contacts     netregex rss

Made by Koshevoy Dmitry [8Bytes],

© 2014-2024 Ukraine, Nikolaev.