Involve regular expressions to solve different kind of tasks regarding text content
Let me introduce a nodejs library called regexp-it-cli - cli tool that provides content searching/filtering functionality by regular expressions. It has plenty of features, some of them will be highlighted in this post.
I am going to demonstrate some use cases where this tool would be applicable.
Regexp playground
You can experiment with regular expression by passing some content as a source and executing your trial regular over it. For example, display only matched parts for specified regexp:

Show some content in slide mode
Have you ever wanted a find functionality without dealing with manually movement handling to the next match but automatically see the next matches with some interval? Slide mode to the rescue! Use the --slide-mode
option optionally providing also --slide-delay
specifying a delay in seconds you'd like:

Filtering content between sections
You can use regexp in a source only after/before specified --after-regexp
and --before-regexp
:
Displaying first and last match
Display only first/last match by providing the --only-first-match
/ --only-last-match
flag
$ regexp-it-cli --url "https://raw.githubusercontent.com/inversify/InversifyJS/master/src/container/container.ts" --regexp "throw.*" -m -q --only-first-match

Using predefined patterns
Use predefined patterns instead of specifying --regexp
yourself by using --regexp-pattern
option.
regexp-it-cli --file "samples/misc.txt" --regexp-pattern "urlLine" -e -m -q

Specify starting/ending line from a source to be used as a content
Apply filter to content that is going to be used a source for a regular expression by using the --starting-line-number
, --ending-line-number
options.

Top comments (0)