github at esdiscuss.org (2013-07-12T02:26:28.064Z)
> So can we make the default behavior of new methods case insensitive?
I think all current methods are case-sensitive. If these methods were to
be made case-insensitive, someone else would come on the list demanding
consistency.
Also, it doesn't seem that hard to implement:
```js
String.prototype.startsWithI = function(s){
this.match(new RegExp('^'+s, 'i'));
}
```
And sometimes, case-sensitive is what you want.
> We should have a String.replaceAll method right now web
> developers are using complex logic to achieve the same.
```js
"aA".replace(/a/ig, 'b'); // 'bb'
```
I feel the `i` and `g` flag or regexps aren't that complex. One just
needs to know about them.
Le 17/02/2013 00:58, Biju a écrit : > In most time when user want to search something in a text, he/she > wants to do a case insensitive search. > For example to filter items displayed in list on a page. > Also on other applications, say any word processor, or in page search > in Firefox, IE, Chrome etc. > > So can we make the default behavior of new methods String.startsWith, > String.contains, String.endsWith case insensitive? I think all current methods are case-sensitive. If these methods were to be made case-insensitive, someone else would come on the list demanding consistency. Also, it doesn't seem that hard to implement: String.prototype.startsWithI = function(s){ this.match(new RegExp('^'+s, 'i')); } And sometimes, case-sensitive is what you want. > And to make it case sensitive we should add a third flag parameter matchCase > like... > > var startsWith = str.startsWith(searchString [, position [, matchCase] ] ); > var contained = str.contains(searchString [, position [, matchCase] ] ); > var endsWith = str.endsWith(searchString [, position [, matchCase] ] ); > > > Additionally we should have a String.replaceAll method right now web > developers are using complex logic to achieve the same. "aA".replace(/a/ig, 'b'); // 'bb' I feel the "i" and "g" flag or regexps aren't that complex. One just needs to know about them. David