Table of Contents

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

Regex

Properties

BrTagCaseInsensitiveRegex

Matches BR tags in HTML (case insensitive by pattern).

public static Regex BrTagCaseInsensitiveRegex { get; set; }

Property Value

Regex

Color6Regex

Matches 6-character hex color codes.

public static Regex Color6Regex { get; set; }

Property Value

Regex

Color8Regex

Matches 8-character hex color codes (with alpha channel).

public static Regex Color8Regex { get; set; }

Property Value

Regex

CzechAccountNumberRegex

Matches Czech bank account numbers in format [prefix-]account/bankCode.

public static Regex CzechAccountNumberRegex { get; set; }

Property Value

Regex

GuidRegex

Matches GUID strings with optional braces.

public static Regex GuidRegex { get; set; }

Property Value

Regex

HtmlCommentRegex

Matches HTML comment blocks.

public static Regex HtmlCommentRegex { get; set; }

Property Value

Regex

HtmlScriptRegex

Matches HTML script tags with their content.

public static Regex HtmlScriptRegex { get; set; }

Property Value

Regex

HtmlTagRegex

Matches HTML tags.

public static Regex HtmlTagRegex { get; set; }

Property Value

Regex

ImgTagRegex

Matches HTML img tags.

public static Regex ImgTagRegex { get; set; }

Property Value

Regex

LastTelephone

Stores the last validated telephone number after calling IsTelephone(string).

public static string? LastTelephone { get; set; }

Property Value

string

NonPairXmlTagsUnvalidRegex

Matches non-pair XML tags that may be invalid.

public static Regex NonPairXmlTagsUnvalidRegex { get; set; }

Property Value

Regex

PreTagWithContentRegex

Matches HTML pre tags with their content.

public static Regex PreTagWithContentRegex { get; set; }

Property Value

Regex

UriRegex

Matches HTTP and HTTPS URIs.

public static Regex UriRegex { get; set; }

Property Value

Regex

WpImgThumbnailRegex

Matches WordPress image thumbnail URLs with dimensions.

public static Regex WpImgThumbnailRegex { get; set; }

Property Value

Regex

YtVideoLinkRegex

Matches YouTube video links and captures the video ID.

public static Regex YtVideoLinkRegex { get; set; }

Property Value

Regex

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

matchCollection MatchCollection

The match collection to extract values from.

groupIndex int

The zero-based index of the capture group to extract.

Returns

List<string>

A list of strings from the specified capture group in each match.

IsColor(string)

Determines whether the specified text is a valid hex color code (6 or 8 characters).

public static bool IsColor(string text)

Parameters

text string

The 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

text string

The 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

text string

The 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

text string

The 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

text string

The 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

text string

The text to check.

Returns

bool

True if the text matches a YouTube video URI pattern; otherwise, false.

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

text string

The 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

text string

The phone number text to sanitize.

Returns

string

The sanitized phone number with country code prefix.