Class RegexHelper
- Namespace
- SunamoRegex
- Assembly
- SunamoRegex.dll
Provides helper methods and precompiled regular expressions for common text validation and pattern matching tasks such as email, URL, phone number, and HTML parsing.
public static class RegexHelper
- Inheritance
-
RegexHelper
- Inherited Members
Fields
WhitespaceRegex
Matches one or more whitespace characters.
public static readonly Regex WhitespaceRegex
Field Value
Properties
BrTagCaseInsensitiveRegex
Matches BR tags in HTML (case insensitive by pattern).
public static Regex BrTagCaseInsensitiveRegex { get; set; }
Property Value
Color6Regex
Matches 6-character hex color codes.
public static Regex Color6Regex { get; set; }
Property Value
Color8Regex
Matches 8-character hex color codes (with alpha channel).
public static Regex Color8Regex { get; set; }
Property Value
CzechAccountNumberRegex
Matches Czech bank account numbers in format [prefix-]account/bankCode.
public static Regex CzechAccountNumberRegex { get; set; }
Property Value
GuidRegex
Matches GUID strings with optional braces.
public static Regex GuidRegex { get; set; }
Property Value
HtmlCommentRegex
Matches HTML comment blocks.
public static Regex HtmlCommentRegex { get; set; }
Property Value
HtmlScriptRegex
Matches HTML script tags with their content.
public static Regex HtmlScriptRegex { get; set; }
Property Value
HtmlTagRegex
Matches HTML tags.
public static Regex HtmlTagRegex { get; set; }
Property Value
ImgTagRegex
Matches HTML img tags.
public static Regex ImgTagRegex { get; set; }
Property Value
LastTelephone
Stores the last validated telephone number after calling IsTelephone(string).
public static string? LastTelephone { get; set; }
Property Value
NonPairXmlTagsUnvalidRegex
Matches non-pair XML tags that may be invalid.
public static Regex NonPairXmlTagsUnvalidRegex { get; set; }
Property Value
PreTagWithContentRegex
Matches HTML pre tags with their content.
public static Regex PreTagWithContentRegex { get; set; }
Property Value
UriRegex
Matches HTTP and HTTPS URIs.
public static Regex UriRegex { get; set; }
Property Value
WpImgThumbnailRegex
Matches WordPress image thumbnail URLs with dimensions.
public static Regex WpImgThumbnailRegex { get; set; }
Property Value
YtVideoLinkRegex
Matches YouTube video links and captures the video ID.
public static Regex YtVideoLinkRegex { get; set; }
Property Value
Methods
AllFromGroup(MatchCollection, int)
Extracts all values from a specific capture group across all matches in a collection.
public static List<string> AllFromGroup(MatchCollection matchCollection, int groupIndex)
Parameters
matchCollectionMatchCollectionThe match collection to extract values from.
groupIndexintThe zero-based index of the capture group to extract.
Returns
IsColor(string)
Determines whether the specified text is a valid hex color code (6 or 8 characters).
public static bool IsColor(string text)
Parameters
textstringThe text to validate as a hex color code.
Returns
- bool
True if the text is a valid hex color code; otherwise, false.
IsEmail(string)
Determines whether the specified text is a valid email address using regex.
public static bool IsEmail(string text)
Parameters
textstringThe text to validate as an email address.
Returns
- bool
True if the text matches the email pattern; otherwise, false.
IsTelephone(string)
Determines whether the specified text is a valid telephone number. Supports formats with optional leading + and 9 or 12 digit numbers. The validated number is stored in LastTelephone.
public static bool IsTelephone(string text)
Parameters
textstringThe text to validate as a telephone number.
Returns
- bool
True if the text is a valid telephone number; otherwise, false.
IsUri(string)
Determines whether the specified text is an HTTP or HTTPS URI.
public static bool IsUri(string text)
Parameters
textstringThe text to check.
Returns
- bool
True if the text is a valid HTTP/HTTPS URI; otherwise, false.
IsValidEmail(string)
Determines whether the specified text is a valid email address using MailAddress.
public static bool IsValidEmail(string text)
Parameters
textstringThe text to validate as an email address.
Returns
- bool
True if the text is a valid email address; otherwise, false.
IsYtVideoUri(string)
Determines whether the specified text is a YouTube video URI.
public static bool IsYtVideoUri(string text)
Parameters
textstringThe text to check.
Returns
- bool
True if the text matches a YouTube video URI pattern; otherwise, false.
ReplacePlainUrlWithLinks(string)
Replaces plain URLs in text with HTML anchor tags. Do not use this method - parsing URIs with regex is naive. Use a DOM parser instead.
public static string ReplacePlainUrlWithLinks(string text)
Parameters
textstringThe plain text containing URLs to convert.
Returns
- string
Text with URLs wrapped in anchor tags.
SanitizePhone(string)
Sanitizes a phone number by removing spaces and adding the +420 country code prefix if missing.
public static string SanitizePhone(string text)
Parameters
textstringThe phone number text to sanitize.
Returns
- string
The sanitized phone number with country code prefix.