Skip to content

Instantly share code, notes, and snippets.

View matthewnitschke's full-sized avatar
⛰️

Matthew matthewnitschke

⛰️
View GitHub Profile
@matthewnitschke
matthewnitschke / patternFormatter.js
Created May 28, 2016 23:55
Takes a value and pattern for input and then returns a formatted string
function formatPattern(value, pattern) {
if (value){
var characters = pattern.replace(getWildcardRegex(), ""); // removes all wild cards
value = value.replace(new RegExp("["+characters+"]", 'gi'), ""); // removes all non wildcard characters in pattern
if (value){
return replace(value, pattern);
}
}
}
@matthewnitschke
matthewnitschke / formatString.js
Last active January 29, 2016 20:45
Formats a string to a pattern
function fomatPattern(value, pattern){
if (value){
var characters = pattern.replace(/#/g, "");
value = value.replace(new RegExp("["+characters+"]", 'gi'), "");
if (value){
return replace(value, pattern);
}
}
}
@matthewnitschke
matthewnitschke / PatternMatches.cs
Last active February 20, 2025 22:21
Simple wildcard matching in C#
public bool MatchesPattern(string pattern, string text)
{
pattern = pattern.Replace("%", @".+");
pattern = pattern.Replace("_", @".");
Regex regex = new Regex(pattern);
if (regex.IsMatch(text))
{
return true;