MustacheSharp/mustache-sharp/RegexHelper.cs

26 lines
814 B
C#
Raw Normal View History

using System;
using System.Text.RegularExpressions;
namespace mustache
{
/// <summary>
/// Provides utility methods that require regular expressions.
/// </summary>
public static class RegexHelper
{
private const string Key = @"[_\w][_\w\d]*";
internal const string CompoundKey = Key + @"(\." + Key + ")*";
/// <summary>
/// Determines whether the given name is a legal identifier.
/// </summary>
/// <param name="name">The name to check.</param>
/// <returns>True if the name is a legal identifier; otherwise, false.</returns>
public static bool IsValidIdentifier(string name)
{
Regex regex = new Regex("^" + Key + "$");
return regex.IsMatch(name);
}
}
}