generated from anexia-it/open-source-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ec2101d
commit a241aa8
Showing
6 changed files
with
176 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// ------------------------------------------------------------------------------------------ | ||
// <copyright file = "AnyExample.cs" company = "ANEXIA® Internetdienstleistungs GmbH"> | ||
// Copyright (c) ANEXIA® Internetdienstleistungs GmbH. All rights reserved. | ||
// </copyright> | ||
// ------------------------------------------------------------------------------------------ | ||
|
||
|
||
namespace Anexia.Gregex.Examples; | ||
|
||
/// <summary> | ||
/// Example for how to use the <see cref="Gregex.Any{T}"/> method for matching any element. | ||
/// </summary> | ||
public static class AnyExample | ||
{ | ||
public static void main() | ||
{ | ||
var listOfWords = new List<string>() | ||
{ | ||
"Hello", | ||
"World", | ||
"This", | ||
"Is", | ||
"A", | ||
"Test", | ||
"For", | ||
"Any", | ||
"Regex" | ||
}; | ||
var anyString = Gregex.Any<string>(); | ||
|
||
var matcher = new Matcher<string>(); | ||
|
||
var matches = matcher.FindMatches(anyString, listOfWords); | ||
|
||
Console.WriteLine(string.Join(Environment.NewLine, matches)); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// ------------------------------------------------------------------------------------------ | ||
// <copyright file = "AtLeastOnceExample.cs" company = "ANEXIA® Internetdienstleistungs GmbH"> | ||
// Copyright (c) ANEXIA® Internetdienstleistungs GmbH. All rights reserved. | ||
// </copyright> | ||
// ------------------------------------------------------------------------------------------ | ||
|
||
namespace Anexia.Gregex.Examples; | ||
|
||
/// <summary> | ||
/// Example of how to use the <see cref="Gregex.AtLeastOnce{T}"/> method to match an element at least once. | ||
/// </summary> | ||
public static class AtLeastOnceExample | ||
{ | ||
public static void main() | ||
{ | ||
var listOfStringWithOneStringRepeated = new List<string>() | ||
{ | ||
"Hello", "World", "Hello", "Hello", "Hello" | ||
}; | ||
|
||
var atLeastOneHello = Gregex.Is("Hello").AtLeastOnce(); | ||
|
||
var matcher = new Matcher<string>(); | ||
|
||
var matches = matcher.FindMatches(atLeastOneHello, listOfStringWithOneStringRepeated); | ||
|
||
Console.WriteLine(string.Join(Environment.NewLine, matches)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// ------------------------------------------------------------------------------------------ | ||
// <copyright file = "FollowedByExample.cs" company = "ANEXIA® Internetdienstleistungs GmbH"> | ||
// Copyright (c) ANEXIA® Internetdienstleistungs GmbH. All rights reserved. | ||
// </copyright> | ||
// ------------------------------------------------------------------------------------------ | ||
|
||
namespace Anexia.Gregex.Examples; | ||
|
||
/// <summary> | ||
/// Example of how to use the <see cref="Gregex.FollowedBy{T}"/> method to match to consecutive elements. | ||
/// </summary> | ||
public static class FollowedByExample | ||
{ | ||
public static void main() | ||
{ | ||
var listOfWords = new List<string> | ||
{ | ||
"This", "is", "a", "test", "of", "Gregex", "followed", "by", "a", | ||
"example", "one", "more", "time", "and", "then", | ||
"we'll", "see", "if", "it's", "working", "This", "is", "not", "a", "test" | ||
}; | ||
|
||
var aTest = Gregex.Is("a").FollowedBy(Gregex.Is("test")); | ||
|
||
var matcher = new Matcher<string>(); | ||
|
||
var matches = matcher.FindMatches(aTest, listOfWords); | ||
|
||
Console.WriteLine(string.Join(Environment.NewLine, matches)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// ------------------------------------------------------------------------------------------ | ||
// <copyright file = "IsExample.cs" company = "ANEXIA® Internetdienstleistungs GmbH"> | ||
// Copyright (c) ANEXIA® Internetdienstleistungs GmbH. All rights reserved. | ||
// </copyright> | ||
// ------------------------------------------------------------------------------------------ | ||
|
||
namespace Anexia.Gregex.Examples; | ||
|
||
/// <summary> | ||
/// Example for matching an element exactly using the <see cref="Gregex.Is{T}"/> method. | ||
/// </summary> | ||
public static class IsExample | ||
{ | ||
public static void main() | ||
{ | ||
var listOfWords = new List<string>() | ||
{ | ||
"Hello", | ||
"World", | ||
"This", | ||
"Is", | ||
"And", | ||
"Test", | ||
"Example", | ||
"List", | ||
"With", | ||
"More", | ||
"Words", | ||
"Like", | ||
"These", | ||
"And", | ||
"Those" | ||
}; | ||
|
||
var gregex = Gregex.Is("And"); | ||
|
||
var matcher = new Matcher<string>(); | ||
|
||
var matches = matcher.FindMatches(gregex, listOfWords); | ||
|
||
Console.WriteLine(string.Join(Environment.NewLine, matches)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,7 @@ | ||
using Anexia.Gregex; | ||
using Anexia.Gregex.Examples; | ||
|
||
var fooBar = "FooBarFooBarFoo".ToCharArray(); | ||
|
||
var twoOs = Gregex.Is('o').Times(2); | ||
|
||
var anyChar = Gregex.Any<char>(); | ||
|
||
var matcher = new Matcher<char>(); | ||
|
||
var oMatches = matcher.FindMatches(twoOs, fooBar).ToArray(); | ||
|
||
Console.WriteLine($"Found: {oMatches.Length} os."); | ||
Console.WriteLine(string.Join("\n", oMatches.AsEnumerable())); | ||
|
||
var anyMatches = matcher.FindMatches(anyChar, fooBar).ToArray(); | ||
|
||
Console.WriteLine($"Found: {anyMatches.Length} matches for any."); | ||
Console.WriteLine(string.Join("\n", anyMatches.AsEnumerable())); | ||
|
||
var anyAtLeastOnce = Gregex.Is('a').AtLeastOnce(); | ||
|
||
var anyAtLeastOnceMatches = matcher.FindMatches(anyAtLeastOnce, ['a', 'a', 'a']).ToArray(); | ||
Console.WriteLine($"Found: {anyAtLeastOnceMatches.Length} matches for at least one any."); | ||
Console.WriteLine(string.Join("\n", anyAtLeastOnceMatches.AsEnumerable())); | ||
|
||
var oFollowedByB = Gregex.Is('o').FollowedBy(Gregex.Is('B')); | ||
|
||
var oFollowedByBMatches = matcher.FindMatches(oFollowedByB, fooBar).ToArray(); | ||
Console.WriteLine($"Found: {oFollowedByBMatches.Length} matches for oB."); | ||
Console.WriteLine(string.Join("\n", oFollowedByBMatches.AsEnumerable())); | ||
|
||
var anyThinkBeforeF = Gregex.Pattern(Gregex.Any<char>(), Gregex.Is('F')); | ||
|
||
var anyThinkBeforeFMatches = matcher.FindMatches(anyThinkBeforeF, fooBar).ToArray(); | ||
Console.WriteLine($"Found: {anyThinkBeforeFMatches.Length} matches for *F."); | ||
Console.WriteLine(string.Join("\n", anyThinkBeforeFMatches.AsEnumerable())); | ||
AnyExample.main(); | ||
IsExample.main(); | ||
TimesExample.main(); | ||
AtLeastOnceExample.main(); | ||
FollowedByExample.main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// ------------------------------------------------------------------------------------------ | ||
// <copyright file = "TimesExample.cs" company = "ANEXIA® Internetdienstleistungs GmbH"> | ||
// Copyright (c) ANEXIA® Internetdienstleistungs GmbH. All rights reserved. | ||
// </copyright> | ||
// ------------------------------------------------------------------------------------------ | ||
|
||
namespace Anexia.Gregex.Examples; | ||
|
||
/// <summary> | ||
/// Example of how to use the <see cref="Gregex.Times{T}"/> method to match an element multiple times. | ||
/// </summary> | ||
public static class TimesExample | ||
{ | ||
public static void main() | ||
{ | ||
var listOfStringWithOneStringRepeated = new List<string>() | ||
{ | ||
"Hello", "World", "Hello", "Hello", "Hello" | ||
}; | ||
|
||
var twoTimesHello = Gregex.Is("Hello").Times(2); | ||
|
||
var matcher = new Matcher<string>(); | ||
|
||
var matches = matcher.FindMatches(twoTimesHello, listOfStringWithOneStringRepeated); | ||
|
||
Console.WriteLine(string.Join(Environment.NewLine, matches)); | ||
} | ||
} |