News for hackers. Stuff that matters.
Re:Show HN: I wrote a book on Python regular expressions by sweeneyrod on Thursday August 08, 2019 @02:26PM (#20647165)
This seems cool, but I think that's mostly because the regex you think of as a point of comparison is something like

    r'^[\w.%+-]+@[\w.-]+\.[a-zA-Z]{2,6}$'
which does look awful. But there's no reason you can't do

    username = r'[\w.%+-]+'
    domain = r'[\w.-]+'
    tld = r'[a-zA-Z]{2,6}'
    email = username + r'@' + domain + r'\.' + tld
which is arguably easier to read than the rxe version for someone familiar with regex.
Re:Show HN: I wrote a book on Python regular expressions by nerdponx on Thursday August 08, 2019 @09:01PM (#20650452)
And/or use verbose mode -- re.VERBOSE or (?x) --for comments and whitespace.
Re:Show HN: I wrote a book on Python regular expressions by jazzyjackson on Thursday August 08, 2019 @03:54PM (#20648019)
wow I didn't know you could concatenate regexes, thanks
Re:Show HN: I wrote a book on Python regular expressions by gnulinux on Thursday August 08, 2019 @04:04PM (#20648101)
Why not? They're just strings until they're compiled. "Code is data"
Re:Show HN: I wrote a book on Python regular expressions by CaptainMarvel on Thursday August 08, 2019 @05:19PM (#20648901)
The thought of doing this literally didn’t occur to me... I think this is great!
Re:Show HN: I wrote a book on Python regular expressions by jazzyjackson on Thursday August 08, 2019 @10:18PM (#20650817)
Well I suppose the r in front of them in python made them look just enough "not a normal string" for me to forget how the + operator might act.

My day-to-day experience is in nodejs, where adding one regex object to another coerces them to normal strings first

[edit: hey neat, the hackernews form strips emoji from comments, I wonder if that's just ranges of unicode or if there's some crazy regex going on :D]

Re:Show HN: I wrote a book on Python regular expressions by baudehlo on Friday August 09, 2019 @09:20AM (#20654016)
In Javascript you just need to wrap in `new RegExp(r1 + r2 + r3)`.
Re:Show HN: I wrote a book on Python regular expressions by Maro on Thursday August 08, 2019 @05:07PM (#20648789)
Yes, an rxe is longer. But: I've been using regexps was 20 years and I can't remember them (both reading and writing). My brain swaps it out, partly bc I know it's one SO away. But that's bad for code readability.