Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Evaluate any text against a collection of match rules

tree: b31c30ada8

Fetching latest commit…

Cannot retrieve the latest commit at this time


Does it match? When regular expressions are not enough, textquery is the answer. For example, regular expressions cannot evaluate recursive rules and often result in overly verbose and complicated expressions.

Textquery is a simple PEG grammar with support for:

  • AND (spaces are implicit AND's)
  • OR
  • NOT (- is an alias)
  • 'quoted strings'
  • fuzzy matching
  • case (in)sensitive
  • custom delimeters

TextQuery in the wild: PostRank, PaperTrail, and others!

Example"'to be' OR NOT 'to_be'").match?("to be")   # => true"-test").match?("some string of text")      # => true"NOT test").match?("some string of text")   # => true"a AND b").match?("b a")                    # => true"a AND b").match?("a c")                    # => false

q ="a AND (b AND NOT (c OR d))")
q.match?("d a b")                                         # => false
q.match?("b")                                             # => false
q.match?("a b cdefg")                                     # => true"a~").match?("adf")                         # => true"~a").match?("dfa")                         # => true"~a~").match?("daf")                        # => true"2~a~1").match?("edaf")                     # => true"2~a~2").match?("edaf")                     # => false"a", :ignorecase => true).match?("A b cD")  # => true


The MIT License - Copyright (c) 2011 Ilya Grigorik

Something went wrong with that request. Please try again.