xegex
Version, currently master branch1 version
- master branchlatestJun 18, 2019
github.com/chenkovsky/xegex
excellent regular expression tool.
3 stars
0 dependents
License: MIT
Installation
# Add this to your shard.yml
dependencies:
xegex:
github: chenkovsky/xegex
branch: mastermaster is a branch, not a release, so this tracks it rather than pinning a version.
Then run:
shards installshard.yml
- Crystal
0.23.1- License
- MIT
- Author
- chenkovsky
Dependencies
This version declares no dependencies.
README
xegex
excellent regular expression tool for crystal, match anything.
Installation
Add this to your application's shard.yml:
dependencies:
xegex:
git: https://github.com/chenkovsky/xegex.git
Usage
require "xegex"
def compile(string : String) : RE(WordToken)
RE(WordToken).compile(string) do |str|
part, quoted_value = str.split("=")
value = quoted_value[1...-1]
RE::Base::Lambda(WordToken).new str do |entity|
case part
when "string"
entity.string.downcase == value
when "postag"
entity.postag == value
when "chunk"
entity.chunk == value
else
raise "Cannot be here"
end
end
end
end
describe Xegex do
it "work" do
sentence = "The US president Barack Obama is travelling to Mexico."
tokens = [
WordToken.new("The", "DT", nil),
WordToken.new("US", "NNP", nil),
WordToken.new("president", "NN", nil),
WordToken.new("Barack", "NNP", nil),
WordToken.new("Obama", "NNP", nil),
WordToken.new("is", "VB", nil),
WordToken.new("travelling", "VB", nil),
WordToken.new("to", "TO", nil),
WordToken.new("Mexico", "NN", nil),
WordToken.new(".", ".", nil),
]
regex = compile("(?:<string='a'> | <string='an'> | <string='the'>)? <postag='JJ'>* <postag='NNP'>+ <postag='NN'>+ <postag='NNP'>+")
found_ = regex.find(tokens)
found_.nil?.should eq(false)
found = found_.not_nil!
found.groups.size.should eq(1)
found[0].tokens.map { |x| x.entity.string }.join(" ").should eq("The US president Barack Obama")
end
end
TODO: Write usage instructions here
Development
TODO: Write development instructions here
Contributing
- Fork it ( https://github.com/chenkovsky/xegex/fork )
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create a new Pull Request
Contributors
- chenkovsky chenkovsky - creator, maintainer
Documentation
Built from the current release. The first visit to a release nobody has asked for starts its build.
Links
This branch
- Branch
master- Seen
- Jun 18, 2019
- Crystal
0.23.1- Indexed
- yes
Dependents
No indexed shard depends on this one yet.
Repository
github.com/chenkovsky/xegex
Metadata
- Created
- Aug 12, 2026
- Updated
- Aug 15, 2026
- Synced
- Aug 15, 2026
- Versions
- 1