Adam Shannon adam at
Mon Jan 2 10:04:31 PST 2012

Alex, I'm confused as to what regular expressions would help with in
this case. (Over .indexOf) The idea of .util() would be to return a
new string which is just a substring, but provided as an "ease of use"
to the developer.

The case where I wrote .util() was in parsing out two comma separated
values. I only needed the first, as could also be seen with trying to
pull the first name (assuming just a first and last name), you could
easily call name.until(' ') and get that back.

On Mon, Jan 2, 2012 at 11:55, Axel Rauschmayer <axel at> wrote:
> Isn’t that usually better handled via a regular expression?
> One of the use cases for quasis [1][2] is to make it easy to insert literal text into a regular expression. That seems pertinent here. Example:
>    re`\d+(${localeSpecificDecimalPoint}\d+)?`
> The text in the variable localeSpecificDecimalPoint is matched literally by the regular expression produced by re``.
> [1]
> [2]
> On Jan 2, 2012, at 18:03 , Adam Shannon wrote:
>> Hello all,
>> I recently ran into a situation where I would like to obtain a
>> substring from the beginning until the first encounter with another
>> substring. This promoted me to write a simple function, called until
>> and I wondered if it would be something to add with the other string
>> extras for
>> It could be defined as acting the same way as the following code:
>> String.prototype.until = function (needle) {
>>  return this.substr(0, this.indexOf(needle));
>> }
> --
> Dr. Axel Rauschmayer
> axel at
> home:
> twitter:
> blog:

Adam Shannon
Web Developer
University of Northern Iowa
Sophomore -- Computer Science B.S. & Mathematics

More information about the es-discuss mailing list