Live data from Hacker News

Show HN: I wrote a book on Python regular expressions

news.ycombinator.com

1–10 of 51 posts

Show HN: I wrote a book on Python regular expressions

#1
My book titled "Python re(gex)?" is free to download through this weekend [1][2]

The book covers both 're' and 'regex' modules, has plenty of examples and chapters also have cheatsheets and exercises.

Code snippets, exercises, sample chapters, etc are available on GitHub repo [3]

I used pandoc+xelatex [4] to generate the pdf.

[1] https://gumroad.com/l/py_regex

[2] https://leanpub.com/py_regex

[3] https://github.com/learnbyexample/py_regular_expressions

[4] https://learnbyexample.github.io/tutorial/ebook-generation/customizing-pandoc/

Re: Show HN: I wrote a book on Python regular expressions

#2
I personally learned RegEx with PowerShell for a work initiative that required heavy usage of it. Most of the documentation regarding RegEx was pretty language agnostic, so it's interesting when I run across guides that are specific to a particular language.

Is there anything about Regular Expressions in Python that creates a unique need for it's own domain specific guide?

Re: Show HN: I wrote a book on Python regular expressions

#4

I personally learned RegEx with PowerShell for a work initiative that required heavy usage of it. Most of the documentation regarding RegEx was pretty language agnostic, so it's interesting when I run across guides that are specific to a particular language. Is there anything about Regular Expressions in Python that creates a unique need for it's own domain specific guide?

There are enough differences in terms of syntax and features across languages that I felt separate books would help the user better than a common one. If you consider Python's built-in 're' module, it doesn't support possessive quantifiers, \K, variable-length lookbehind, set operations, control verbs like SKIP, \p{} unicode character sets and so on.

Another angle is with regards to usage of functions. When to use 're.findall' vs 're.finditer'. How does capture group affect 're.split' and 're.findall' and so on.

Re: Show HN: I wrote a book on Python regular expressions

#5

I personally learned RegEx with PowerShell for a work initiative that required heavy usage of it. Most of the documentation regarding RegEx was pretty language agnostic, so it's interesting when I run across guides that are specific to a particular language. Is there anything about Regular Expressions in Python that creates a unique need for it's own domain specific guide?

It is not really the regex syntax itself that changes (not too many python specific constructs), but rather, how you apply it. For example, you might use capture groups and re.findall, which will return a list of tuples, or re.search, which will return a match object, both of which have different ways of iterating.

Re: Show HN: I wrote a book on Python regular expressions

#7
You might like:

https://github.com/mtrencseni/rxe

So you can write:

  username = rxe.one_or_more(rxe.set([rxe.alphanumeric(), '.', '%', '+', '-']))
  domain = rxe.one_or_more(rxe.set([rxe.alphanumeric(), '.', '-']))
  tld = rxe.at_least_at_most(2, 6, rxe.set([rxe.range('a', 'z'), rxe.range('A', 'Z')]))
  email = (rxe
    .exactly(username)
    .literal('@')
    .exactly(domain)
    .literal('.')
    .exactly(tld)
  )

Re: Show HN: I wrote a book on Python regular expressions

#10
post #7

You might like: https://github.com/mtrencseni/rxe So you can write: username = rxe.one_or_more(rxe.set([rxe.alphanumeric(), '.', '%', '+', '-'])) domain = rxe.one_or_more(rxe.set([rxe.alphanumeric(), '.', '-'])) tld = rxe.at_least_at_most(2, 6, rxe.set([rxe.range('a', 'z'), rxe.range('A', 'Z')])) email = (rxe .exactly(username) .literal('@') .exactly(domain) .literal('.') .exactly(tld) )

Never heard about the rxe but it looks like something I could use - thanks.
Post reply on HN