Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/igrigorik/textquery
Evaluate any text against a collection of match rules
https://github.com/igrigorik/textquery
Last synced: 3 days ago
JSON representation
Evaluate any text against a collection of match rules
- Host: GitHub
- URL: https://github.com/igrigorik/textquery
- Owner: igrigorik
- Created: 2009-12-28T21:16:26.000Z (about 15 years ago)
- Default Branch: master
- Last Pushed: 2013-10-30T05:59:21.000Z (about 11 years ago)
- Last Synced: 2025-01-01T11:07:10.894Z (10 days ago)
- Language: Ruby
- Homepage:
- Size: 290 KB
- Stars: 144
- Watchers: 5
- Forks: 9
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# TextQuery
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
- attribute tags (e.g. surname:Smith)
- custom delimiters (default is whitespace for words, : for attributes)TextQuery in the wild: [PostRank](http://postrank.com/), [PaperTrail](https://papertrailapp.com/), and others!
## Example
```ruby
TextQuery.new("'to be' OR NOT 'to_be'").match?("to be") # => trueTextQuery.new("-test").match?("some string of text") # => true
TextQuery.new("NOT test").match?("some string of text") # => trueTextQuery.new("a AND b").match?("b a") # => true
TextQuery.new("a AND b").match?("a c") # => falseq = TextQuery.new("a AND (b AND NOT (c OR d))")
q.match?("d a b") # => false
q.match?("b") # => false
q.match?("a b cdefg") # => trueTextQuery.new("a~").match?("adf") # => true
TextQuery.new("~a").match?("dfa") # => true
TextQuery.new("~a~").match?("daf") # => true
TextQuery.new("2~a~1").match?("edaf") # => true
TextQuery.new("2~a~2").match?("edaf") # => falseTextQuery.new("a", :ignorecase => true).match?("A b cD") # => true
```## License
The MIT License - Copyright (c) 2011 Ilya Grigorik