Giter Site home page Giter Site logo

hlre's Introduction

hlre

Interactively highlight regular expression matches.

What?

A TUI application that shows the matches of a (python-flavored) regular expression as you type it.

Why?

I really like using RegExr, but it uses the javascript regex engine and there are some subtle differences between the results there and what you get with python.

Installation

python3 -m pip install hlre

Usage

TLDR

  1. Run

    hlre -f nginx.log
    
  2. Type a regex and see the matches highlighted in nginx.log.

  3. Press Control-C to exit.

Input Sources

You can either highlight matches with the built-in example text, a string passed on the command line, or in an external file.

  • Built-in Demo Text

    hlre --demo-text
    
  • String

    hlre --text 'This is the regular expression subject.'
    
  • External File

    hlre --file nginx.log
    

    Reading in the whole file can slow this tool down quite a bit, so you probably want to do something like:

    hlre --file <(head -n 10 nginx.log)
    

    To look at just the first 10 lines.

Highlighting All Matches

By default, each line is treated as a seperate subject to match the regex on.

To highlight all matches in the subject, use the -a flag:

hlre --demo-text -a
# OR
hlre --file nginx.log --all

This uses re.finditer and the re.MULTILINE flag under the hood.

Customizing Highlight Styles

hlre uses prompt toolkit's HTML functionality, so any tag name that works there should work here. This tool does not currently support any custom attributes on tags (e.g style="...").

Here are some examples:

  • Underline the entire match, highlight capture groups in a dark red

    hlre --demo-text --highlight-style u --group-highlight-style firebrick
    
  • Highlight the entire match in green, bold the capture groups

    hlre --demo-text -s green -g b
    
  • Italicize the entire match, highlight capture groups in cyan

    hlre --demo-text -s i -g cyan
    

hlre's People

Contributors

zgulde avatar

Stargazers

Thomas Leary avatar Balázs Cene avatar Nicholas Dougherty avatar  avatar Gabby  avatar Fernando Mendoza R. avatar Kwame Violet Taylor avatar

Watchers

 avatar

Forkers

aliciag92

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.