Skip to content

Latest commit

 

History

61 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pattern to regex app

This application translates a string sequence with tokens (greedy, lazy) into a regex

Installation

This application uses nix to encapsulate all necessary packages required to run this program. It can be download using:

sh <(curl -L https://nixos.org/nix/install) --daemon

To start nix use the command:

nix-shell

If nix-shell isn't recognised, please restart the terminal.

To use Elixir run

mix deps.get --all

and to build the code:

mix

Finally to run the program use:

cat input.txt |  sh program "foo %{0} is a %{1S3}" > output.txt

To generate docs run:

mix docs

Notes

To run the program based on the specification, there is a bash script called program. This is so the terminal can be used to cat the data from the file input.txt into program (bash script).

From here the bash script calls the Elixir module which encapsulates the logic for taking a string with tokens and building a regex based on a basic algorithm that looks at the string values and determines the token type (standard, greedy, lazy etc). This part of the code has unit tests to verify the creation of the regex works correctly.

There are token parser files for the different token types. The idea is if there is a new token type, the engineer would follow the same pattern and create a new <token_type>.ex file.

The regex string is outputted from the Elixir module and used with pcre2grep which writes all the correct matches to output.txt

Combinations

Value Regex
word (<word>)
space <space_characteer>
simple token [a-zA-Z0-9_]+
limited token ([a-zA-Z0-9]+[^a-zA-Z0-9]*){1,#{number}}$
greedy token .*

The string `The %{0} brown fox was %{1G} and neither %{2} nor %{3S2}' would translate to:

(The) [a-zA-Z0-9_]+ (brown) (fox) (was) .* (and) (neither) [a-zA-Z0-9_]+ (nor) ([a-zA-Z0-9]+[^a-zA-Z0-9]*){1,3}$ 

About

Elixir app that takes a sequence from command line and translates it to a regex

Resources

Stars

4 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages