4 ms·
Do you have a tutorial or article you recommend to read up on x-modifier?
by wodenokoto 6y ago
Do you have a tutorial or article you recommend to read up on x-modifier?
- amarshall 6y agoImplementation may vary, check your regex library’s docs (usually listed under “flags”). Generally there’s not much to it; specify the flag and then whitespace and some form of comment within the string is ignored.
- brigandish 6y agoMy favourite regex site is Rexegg[1]. I thought it had died so I was using archive.org but it appears to be back. Unmatched, in my opinion. Still, there's not much to the `x` modifier, you just need to know that it will ignore implicit whitespace and comments (# blah blah) so you must use `\s` or `\t` etc when you really want to match some whitespace. Otherwise you can do things like: "Hello, world!".split(/ [ \s , ]+ # this splits on at least one space or comma /x) Which is overkill for a simple pattern (then again, why not?) but unbelievably useful for a complex one. Add spaces and newlines until it's readable. It's a small change but a big effect. [1] https://www.rexegg.com/regex-modifiers.html https://www.rexegg.com/regex-modifiers.html