Re:Regular Expressions make me feel like a powerful wizard- ...
by goguy on Friday February 10, 2023 @01:31AM
(#34736345)
That's less readable than the original suggestion though.
Re:Regular Expressions make me feel like a powerful wizard- ...
by sundarurfriend on Friday February 10, 2023 @01:56AM
(#34736518)
Out of context on HN, it looks so. But in my experience, the original suggestion with the separate variables gets pretty hard to keep track of, and ends up making things more confusing. The `(?x)` or `/.../x` version makes it much easier to see things in their place and understand the overall pattern.
Re:Regular Expressions make me feel like a powerful wizard- ...
by RheingoldRiver on Friday February 10, 2023 @03:01PM
(#34744963)
That's pretty neat, indeed I'd never heard of this, or maybe I had once but I'd forgotten about it if so. I might counter that in a very long regex you'd want to do the assembly in multiple steps, but I can definitely see the appeal of inline comments (perhaps in addition to something like that). I'll try to keep this in mind for the next time I'm dealing with regex. Thanks for sharing!
We can write the regex like this, including all whitespace:
Also, btw, I hope no one is really using this regex. It's wrong; for example it appears to be deliberately designed to fail on IDNs.