Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
= tre-ruby
tre-ruby is a Ruby binding for TRE library which is "a lightweight, robust, and efficient POSIX compliant regexp matching library with some exciting features such as approximate (fuzzy) matching." Since Ruby has builtin regexp support, this gem will only provide the interface for approximate matching, which is missing in Ruby.
== Prerequisite
== Installation
gem install tre-ruby
== Setting up TRE is an extension module for String. You can extend a String object with it, or include it into String class
require 'tre-ruby'
"Clamshell".extend(TRE).ascan /shll/, TRE.fuzziness(2)
class String include TRE end
"Clamshell".ascan /shll/, TRE.fuzziness(2)
== Approximate matching TRE module provides the following instance methods.
=== Methods
TRE#axxx methods behave similar to their String#xxx counterparts, except that you cannot make use of virtual global variables ($&, $`, $', ...)
=== TRE::AParams
Every `a-method' of TRE takes a TRE::AParams object as its last parameter. TRE::AParams controls the approximate matching.
params = TRE::AParams.new params.max_err = 3
str.extend(TRE).ascan /abracadabra/, params
There is a shortcut class method TRE.fuzziness(n) which is good enough for most cases. It returns a frozen TRE::AParams object with max_err of n.
str.extend(TRE).ascan /abracadabra/, TRE.fuzziness(3)
== Examples
=== TRE#aindex, TRE#afind You can locate the pattern (String or Regexp) in the string with aindex and afind. When the pattern is not found, nil is returned.
str = <<-EOF She sells sea shells by the sea shore. The shells she sells are surely seashells. So if she sells shells on the seashore, I'm sure she sells seashore shells. EOF
str.aindex 'shll', 0, TRE.fuzziness(1) # (4...8)
str.afind 'shll', 0, TRE.fuzziness(1) # "sell"
str.afind 'shll', 10, TRE.fuzziness(1) # "shell"
str.aindex /s[hx]ll/, 0, TRE.fuzziness(1) # (4...8)
=== TRE#ascan When the pattern is not found, an empty Array is returned.
str.ascan /SSELL/i, TRE.fuzziness(2) # [" sell", "shell", "shell", " sell", "shell", " sell", "shell", " sell"]
str.ascan /(SS)(E)LL/i, TRE.fuzziness(2) # [[" sell", " s", "e"], ["shell", "sh", "e"], ["shell", "sh", "e"], # [" sell", " s", "e"], ["shell", "sh", "e"], [" sell", " s", "e"], # ["shell", "sh", "e"], [" sell", " s", "e"]]
str.ascan /SSELL/i, TRE.fuzziness(2) do | match_string | puts match_string end
str.ascan /(SS)(E)LL/i, TRE.fuzziness(2) do | first, second | puts "#{first} => #{second}" end
=== TRE#asub, TRE#agsub
Substitutions.
str.asub 'shll', '______', TRE.fuzziness(2)
str.asub /(SS)(E)LL/i, "(\2 / \1)", TRE.fuzziness(2) str.agsub /(SS)(E)LL/i, "(\2 / \1)", TRE.fuzziness(2)
=== Fine-grained control of approximate matching parameters
aparams = TRE::AParams.new { |ap| ap.cost_ins = 1 ap.cost_del = 1 ap.cost_subst = 2
ap.max_ins = 10
ap.max_del = 20
ap.max_subst = 15
ap.max_err = 30
ap.max_cost = 50
} str.ascan(/sea shells/, aparams)
== Contributing to tre-ruby
== Copyright
Copyright (c) 2011 Junegunn Choi. See LICENSE.txt for further details.
FAQs
Unknown package
We found that tre-ruby demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.