Code Monkey home page Code Monkey logo

fuzzyregexp's Introduction

fuzzy-regexp

fuzzy-regexp: Fuzzy-matching regexp generator for Emacs

Copyright (C) 2014 Hisashi Morita

Synopsis

(fuzzy-regexp STR &optional WORD-MATCH SELF-INCLUSIVE)

Generate regexp to match strings that are modification of STR by one character.

  • If WORD-MATCH is true, regexp tries to match whole words only (not substrings).
  • If SELF-INCLUSIVE is true, regexp alsos matches STR itself.

Examples

Plain use without options.

(fuzzy-regexp "the")
;;=> "[^t]he\\|te\\|th[^e]\\|t.he\\|th.e\\|t[^h]e\\|hte\\|teh"
;;   Matches "teh", "thi", "this", etc.
;;   Does not match "the" itself.

Enable word-match option for word-oriented match. (This may not work as intended for languages such as Chinese or Japanese.)

(fuzzy-regexp "the" t nil)
;;=> "\\b\\(?:[^t]he\\|te\\|th[^e]\\|t.he\\|th.e\\|t[^h]e\\|hte\\|teh\\)\\b"
;;   Matches "teh", "thi", etc.
;;   Does not match substrings within words such as "thi" in "this".
;;   Does not match "the" itself.

Enable self-inclusive option to match the search keyword itself.

(fuzzy-regexp "the" nil t)
;;=> "the\\|[^t]he\\|te\\|th[^e]\\|t.he\\|th.e\\|t[^h]e\\|hte\\|teh"
;;   Matches "teh", "thi", "this", etc.
;;   Matches "the" itself.

If you want case-sensitive/insensitive search, set case-fold-search.

(let ((case-fold-search t))
  (search-forward-regexp (fuzzy-regexp "the")))
;;=> Matches "Teh", "teh", "Thi", "thi", "This", "this", etc.
;;   Does not match "The" or "the".

Installation

  1. Copy fuzzy-regexp.el to somewhere in load-path.
  2. Add (require 'fuzzy-regexp) to your init file, e.g. ~/.emacs.d/init.el.
  3. Restart Emacs.

Motivation

I needed a fuzzy matching library which can exclude query keyword itself from the result, in order to find typographical errors in natural language text, but could not find one. So I hacked up this kludge.

References

Fuzzy/ambiguous/approximate matching libraries and applications that I know of:

You may want to try these first.

fuzzyregexp's People

Contributors

hisashim avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.