random_string_generator v0.1.1 RandomStringGenerator View Source

A Module to generate a random string based on a given string pattern

Accepted string patterns:

Use l for lower case letter from a to z
Use L for upper case letter from A to Z
Use d for digit from 0 to 9
Use p for punctuation

Punctuation is any character on the following group:

@punctuation [
    "!", """, "#", "$", "%", "&", "'", "(", ")", "*", "+", ",", "-",
    ".", "/", ":", ";", "<", "=", ">", "?", "@", "[", "\", "]", "^",
    "_", "`", "{", "|","}", "~"
]

Generate a string containing 2 lower case letters followed by 2 digits.

RandomStringGenerator.generate("lldd")

Generate a string containing 2 upper case letters.

RandomStringGenerator.generate("LL")

Delimiters

Everything that is not l,L,d and p is treated as a delimiter so the pattern -dl? is interpreted as a hyphen followed by a digit followed by a letter followed by a question mark.

Generate a string containing 2 letters followed by a hyphen.

RandomStringGenerator.generate("ll-")

Scape

In order to generate a string containing the characters l,L,d and p as a delimiter you need to use the backslash twice in order to scape it.

Generate a string containing 2 digits followed by the letters lLdp.

RandomStringGenerator.generate("dd\\l\\L\\d\\p")

Link to this section Summary

Functions

Given a pattern string, returns a random generated string

Link to this section Functions

Given a pattern string, returns a random generated string.

Examples

iex> str = RandomStringGenerator.generate("l-L-d")
iex> Regex.match?(~r/[a-z]-[A-Z]-[0-9]/, str)
true