New answers tagged

2

Probably because that's how regular expression flags are handled in most text editors and other programming languages. A lot of things about regular expressions make more sense when you're using them in a text editor such as vim, where almost all actions are keyboard-driven. For example, in vim if I type :s/foo/bar/g and press enter, all instances of foo ...


-5

If you have to ask, the answer is yes. Suppose some FNG comes along and thinks he can "improve" your regex. Now, he's a FNG, so automatically an idiot. Exactly the kind of person who should not touch your precious code under any circumstances, ever! But maybe he's related to the PHB or something, so there's nothing you can do. Except you know the PHB is ...


3

Regular expressions are code along with the rest of your application. You should test that the code overall does what you expect it to do. This has several purposes: Test are runnable documentation. It clearly demonstrates what you need the code to do. If it is tested it is important. Future maintainers can be certain that if they modify it, the tests ...


1

In short, you should test your application, period. Whether you test your regex with automated tests that run it in isolation, as part of a bigger black box or if you just fiddle around with it by hand is secondary to the point that you need to make sure it works. The main advantage of unit tests is that they save time. They let you test the thing as many ...


21

Regex can be a powerful tool, but it is not a tool you can trust to just still work if you make even minor changes to complex regexes. So create lots of tests that documents the cases that it should cover. And create lots of tests that documents cases it should fail, if it is used for validation. Whenever you need to change your regexes you add the new ...


99

Testing dogmatism aside, the real question is whether it provides value to unit test complex regular expressions. It seems pretty clear that it does provide value (regardless of whether the regex is part of a public interface) if the regex is complex enough, since it allows you to find and reproduce bugs and prevent against regressions.


-2

On the other hand: they themselves are seldom part of the interface of some unit. It might be better to only test the interface and do that in a way that implicitly tests the regexes. I think with this you answered it yourself. Regexes in a unit are most likely an implementation detail. What goes for testing your SQL probably also goes for regexes. ...


1

urlize is restrictive because it works with content which, in substance, is very different compared to SMS. The goal of urlize is to be restrictive, because: Developers would usually include the scheme by themselves, They won't be very annoyed if they don't and urlize will consider that example.com is not a valid URI, while http://example.com is. They will ...



Top 50 recent answers are included