<commit_before>define ["jquery", "lib/forms/validators", "lib/forms/error_messages"], ($, Validators, ErrorMessages) ->

  class InputValidator

    constructor: (input, label, validator) ->
      @input = input
      @label = label
      @validator = validator
      @_initialize() if @input and @label and @validator

    isValid: ->
      Validators[@name](@input, @args)

    getErrorMessage: ->
      "#{@_replace(ErrorMessages[@name], @args)} #{@label}" 

    _initialize: ->
      # check for validation rules that have parameters and split them up, e.g. min(3)
      if match = @validator.match(/(.+)\((.+)\)/)
        @name = match[1]
        @args = match[2]
      else
        @name = @validator

    _replace: (text, variables) ->
      text.replace /{(\d+)}/g, (match, number) ->
        if typeof variables[number] != 'undefined' then variables[number] else match<commit_msg>Make the match for the braces non greedy to allow for regex grouping in validator rules.<commit_after>define ["jquery", "lib/forms/validators", "lib/forms/error_messages"], ($, Validators, ErrorMessages) ->

  class InputValidator

    constructor: (input, label, validator) ->
      @input = input
      @label = label
      @validator = validator
      @_initialize() if @input and @label and @validator

    isValid: ->
      Validators[@name](@input, @args)

    getErrorMessage: ->
      "#{@_replace(ErrorMessages[@name], @args)} #{@label}" 

    _initialize: ->
      # check for validation rules that have parameters and split them up, e.g. min(3)
      if match = @validator.match(/(.+?)\((.+)\)/)
        @name = match[1]
        @args = match[2]
      else
        @name = @validator

    _replace: (text, variables) ->
      text.replace /{(\d+)}/g, (match, number) ->
        if typeof variables[number] != 'undefined' then variables[number] else match
{'fraction_non_alphanumeric': 0.1553398058252427, 'fraction_numerical': 0.003236245954692557, 'mean_word_length': 2.8565488565488564, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1084842', 'n_tokens_mistral': 561, 'n_tokens_neox': 548, 'n_words': 156}