I think it can be done by generating strings using brute force and then try to match them to the supplied regex and printing if match.
But is there a better way to do this?
Regex are used to test if a string matches a pattern. I am aware of that. I thought it would be interesting to do it the way around.
Well you need to escape it, creating the regular expression \\ . To create that regular expression, you need to use a string, which also needs to escape \ . That means to match a literal \ you need to write "\\\\" — you need four backslashes to match one!
In JavaScript, regular expressions are often used with the two string methods: search() and replace() . The search() method uses an expression to search for a match, and returns the position of the match. The replace() method returns a modified string where the pattern is replaced.
Regular expressions are used with the RegExp methods test() and exec() and with the String methods match() , replace() , search() , and split() .
[] denotes a character class. () denotes a capturing group. [a-z0-9] -- One character that is in the range of a-z OR 0-9.
If you're using JavaScript, there's Randexp which generates random strings that match a given regex.
Releases for browser
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With