News for hackers. Stuff that matters.
Re:RegExp Lookbehind Assertions by lolc on Monday February 29, 2016 @06:13PM (#11199510)
What do you mean by "usually"? What situation calls for this? I wonder why people seem to consider this a worthy addition where in my view it only serves to complicate the implementation.

From what I see these additions become useful long past the point where using a regex was sensible in the first place.

Re:RegExp Lookbehind Assertions by solipsism on Monday February 29, 2016 @06:47PM (#11199715)
I've used lookbehind assertions (and negative lookbehind assertions) many times. Most recently I used them to do some complex find/replaceing across a pretty large codebase. My editor supports regex, and I'm glad it does because it made the job easy.

From what I see these additions become useful long past the point where using a regex was sensible in the first place.

Regex stops being a sensible solution when your pattern starts getting overly complex. The fact that you use one of these features doesn't imply your pattern is overly complex. These are not complex features, they're easy to use, and often extremely useful. For example when straightforward find/replace doesn't cut it. What would you suggest, I take 10 minutes to write a Python script for what took me about 15 seconds in my editor's Find/Replace box?

Re:RegExp Lookbehind Assertions by lolc on Monday February 29, 2016 @08:56PM (#11200300)
I see how this can be useful for ad-hoc replacements.

To clarify, I'm not asking about the usefulness of the feature in general but why it makes sense to add this to JS.

Re:RegExp Lookbehind Assertions by paulddraper on Tuesday March 01, 2016 @02:17AM (#11201216)
Because JS is a general purpose language?
Re:RegExp Lookbehind Assertions by mioelnir on Monday February 29, 2016 @07:02PM (#11199788)
I once argued that it `could not be so hard to write a regexp that validates Debian package versions`. Ohboy. Let's just say that in the end it became a point of pride to come up with something.

Debian package version numbers have leading and trailing optional parts and if they are specified, then the characters used as separator of these parts are allowed as part of the version number.

The resulting regexp ended up being essentially four different regexp expressions with four leading conditions utilizing look-ahead and look-behind matching to select which inner regexp to use. It was sufficiently beyond actually regular, even if supported by modern RE tools.

And this is a common pattern in my experience. If you frequently need look-ahead or look-behind, you are often past something you should reasonably disassemble using regexp and should instead start defining a grammar and parse the input stream against it.

Re:RegExp Lookbehind Assertions by paulddraper on Tuesday March 01, 2016 @02:12AM (#11201207)
The Debian version format was not made to be easy.

https://www.debian.org/doc/debian-policy/ch-controlfields.ht...

But in any case, this works.

  ^(\d+:|(?!.*:))(?!.*-[^-]*:[^-]*$)\d(-?[A-Za-z0-9.+:~])*$
Actually, I think I variable-width lookbehind might be handy here to check the hyphens, but I don't have Chrome 49, so I'll forgo it.
Re:RegExp Lookbehind Assertions by mioelnir on Monday March 07, 2016 @08:56PM (#11243114)
I'd contend that it was "made" at all.

When I first looked at the relevant section of the policy manual, my takeaway was that they had a script that iteratively removed the leading and trailing optional fields, making use of the separators safe only if the fields were there so the script did not misfire.

They then took the runtime behavior of that existing script and called it the standard.