Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Even in the OP, the author is already using NSRegularExpression, because Swift doesn't have regular expressions built in.

And if Next can write NSRegularExpression, anyone can write their own library that uses a better syntax and that supports interpolation.

There's also no reason why a pure library has to make a single string its interface. For instance, in Python I might use overloaded operators:

    ((R('foo') | 'bar') + 'tholeme' + {'w', 'W'})[1:7]
to mean:

    r'((foo|bar)tholeme[wW]){1,7}'
There are some rough edges because you're abusing operator overloading, for sure, but expressing a regex is fundamentally composing assertions with operators. It doesn't _require_ any special syntax.

And some languages give you a lot of power to write your own DSLs that will feel more native, e.g. Scheme[1], Haskell[2], Ruby and so forth.

[1]: https://docs.racket-lang.org/guide/macros.html

[2]: https://wiki.haskell.org/Template_Haskell



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: