Skip to content

Instantly share code, notes, and snippets.

@xkef xkef/image.svg
Last active Apr 20, 2019

Embed
What would you like to do?
regex.md
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Regex tricks

https://regexper.com image.svg is from there

regex visualizer

exrex: generate words from regex

regexr: teaching

http://www.pyregex.com/



- negative lookahead: ^(?!.*bar).*$

e.g.: cut out "id": n in json

^(?!.*("id": ".*.")).*$

- passwords: 

             ^(?=.*?[A-Z]{2,})  # min. 2 upper case
              (?=.*?[a-z]{2,})  # min. 2 lower case
              (?=.*?[0-9]{2,})  # min. 2 numericals
              .{8,8}$           # length between 8,8 => 8
              
              ^(?=.*?[A-Z]{2,})(?=.*?[a-z]{2,})(?=.*?[0-9]{2,})(?!.*(.).*\1).{8,8}$ 
              
              inserting (?!.*(.).*\1) constraints word to be only of unique characters
              
            (
               (
               (
                (?=.*?[A-Z]
               ).{2,}
              )
              (
                (?=.*?[a-z])
                .{2,}
              )
              (
                (?=.*?[0-9])
                .{2,}
              )
                )(?!.*(.).*\1)
            )
            .{8,8}$ 
            
            => ((((?=.*?[A-Z]).{2,})((?=.*?[a-z]).{2,})((?=.*?[0-9]).{2,}))(?!.*(.).*\1)).{8,8}$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.