Table of Contents

Class WildcardExpression

Namespace
Acuit.Pinpoint.Common.WildcardExpressions
Assembly
Acuit.Pinpoint.Common.dll

A wildcard expression.

[Obsolete("This is deprecated and will be removed in a future version; Acuit.Pinpoint.WildcardExpressions.WildcardExpression should be used instead.")]
public class WildcardExpression
Inheritance
WildcardExpression
Inherited Members

Remarks

This general-purpose wildcard mechanism can be used stand-alone to match strings, or it can be used to generate equivalent matching mechanisms for use elsewhere:

  • Regular expressions.
  • SQL LIKE patterns. NOTE: Not all wildcard expressions have equivalent SQL LIKE patterns.
  • Expressions for use in Linq database queries.

The following are supported in wildcard expressions:

Pattern Description
* Zero or more characters
? Any one character
[AB] One character from a set
[0-9] One character from a range
[0-9ABCDEF] Combination of the above
[^AB] One character not from a set or range
ALT1|ALT2 Alternatives for the overall string
PRE(ALT1|ALT2)POST Alternatives within the overall string
\ Treat the next character as a literal
{name} A named capture (optional)
/regex/ A regular expression (the entire pattern must be enclosed in slashes)

Constructors

WildcardExpression(string)

Initializes a new instance of the WildcardExpression class.

public WildcardExpression(string pattern)

Parameters

pattern string

The wildcard pattern.

Remarks

See the remarks for WildcardExpression for supported wildcard expressions.

Exceptions

ArgumentNullException

pattern is null.

ArgumentException

pattern is not a valid wildcard.

WildcardExpression(string, bool)

Initializes a new instance of the WildcardExpression class.

public WildcardExpression(string pattern, bool supportCaptures)

Parameters

pattern string

The wildcard pattern.

supportCaptures bool

Whether to support captures in the wildcard pattern.

Remarks

See the remarks for WildcardExpression for supported wildcard expressions.

Exceptions

ArgumentNullException

pattern is null.

ArgumentException

pattern is not a valid wildcard.

Properties

IsLiteral

Gets whether the wildcard expression is a literal string.

public bool IsLiteral { get; }

Property Value

bool

Remarks

ToLiteral() can be used to get the equivalent literal string.

Pattern

Gets the wildcard pattern.

public string Pattern { get; }

Property Value

string

RegexPattern

Gets the regular expression pattern for this wildcard expression.

public string RegexPattern { get; }

Property Value

string

Methods

Escape(string)

Escapes literal text for use within a wildcard pattern.

public static string Escape(string text)

Parameters

text string

The text to escape.

Returns

string

The escaped text.

Exceptions

ArgumentNullException

text is null.

Escape(string, bool)

Escapes literal text for use within a wildcard pattern.

public static string Escape(string text, bool supportCaptures)

Parameters

text string

The text to escape.

supportCaptures bool

Whether to support captures in the wildcard pattern.

Returns

string

The escaped text.

Exceptions

ArgumentNullException

text is null.

IsMatch(string)

Determines whether text matches the wildcard pattern.

public bool IsMatch(string text)

Parameters

text string

The text to compare to the wildcard pattern.

Returns

bool

Returns true if the text matches the wildcard pattern.

Remarks

Comparisons are case-insensitive. To perform case-sensitive comparisons, create a Regex object with the desired options, using RegexPattern as the regular expression pattern.

Exceptions

ArgumentNullException

text is null.

IsMatch(string, string)

Determines whether input text matches a wildcard pattern.

public static bool IsMatch(string input, string pattern)

Parameters

input string

The text to compare to the wildcard pattern.

pattern string

The wildcard pattern.

Returns

bool

Returns true if the input text matches the wildcard pattern.

Remarks

Comparisons are case-insensitive. To perform case-sensitive comparisons, create a Regex object with the desired options, using RegexPattern as the regular expression pattern.

See the remarks for WildcardExpression for supported wildcard expressions.

Exceptions

ArgumentNullException

input is null.

ArgumentNullException

pattern is null.

ArgumentException

pattern is not a valid wildcard.

ToLiteral()

Convert the wildcard expression to a literal string, is possible.

public string ToLiteral()

Returns

string

The equivalent literal string.

Remarks

If the wildcard expression contains anything other than literal string characters, then this will throw a NotSupportedException.

Exceptions

InvalidOperationException

The wildcard expression cannot be converted to a literal string.

ToSqlLikePattern()

Convert the wildcard expression to a SQL LIKE pattern, is possible.

public string ToSqlLikePattern()

Returns

string

The equivalent SQL LIKE pattern.

Remarks

The following cannot be converted to a SQL LIKE pattern:

Pattern Description
ALT1|ALT2 Alternatives for the overall string
PRE(ALT1|ALT2)POST Alternatives within the overall string
{name} A named capture (optional)
/regex/ A regular expression (the entire pattern must be enclosed in slashes)

Exceptions

NotSupportedException

The wildcard expression cannot be converted to a SQL LIKE pattern.

ToSqlWhereMatchExpression(Expression, Func<Expression, string, Expression>)

Convert the wildcard expression to an expression for use in Linq database queries, is possible.

public Expression ToSqlWhereMatchExpression(Expression sourceValueExpression, Func<Expression, string, Expression> sqlLikeFactory)

Parameters

sourceValueExpression Expression
sqlLikeFactory Func<Expression, string, Expression>

Returns

Expression

The equivalent SQL LIKE pattern.

Remarks

The following cannot be converted to an expression for use in Linq database queries:

Pattern Description
PRE(ALT1|ALT2)POST Alternatives within the overall string
{name} A named capture (optional)
/regex/ A regular expression (the entire pattern must be enclosed in slashes)

Exceptions

NotSupportedException

The wildcard expression cannot be converted to an expression for use in Linq database queries.

ToString()

Returns the Pattern value as a string that represents the current object.

public override string ToString()

Returns

string

A string that represents the current object.