Skip to content

Commit 2f60f20

Browse files
committed
add global regex in underscore method
1 parent 606fe8f commit 2f60f20

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

lib/string.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ string.js - Copyright (C) 2012-2014, JP Richardson <[email protected]>
602602

603603
//#modified from https://github.com/epeli/underscore.string
604604
underscore: function() {
605-
var s = this.trim().s.replace(/([a-z\d])([A-Z]+)/g, '$1_$2').replace(/([A-Z\d]+)([A-Z][a-z])/,'$1_$2').replace(/[-\s]+/g, '_').toLowerCase();
605+
var s = this.trim().s.replace(/([a-z\d])([A-Z]+)/g, '$1_$2').replace(/([A-Z\d]+)([A-Z][a-z])/g,'$1_$2').replace(/[-\s]+/g, '_').toLowerCase();
606606
return new this.constructor(s);
607607
},
608608

test/string.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,7 @@
755755
T (S('_CarSpeed').underscore().s === '_car_speed');
756756
T (S('yesWeCan').underscore().s === 'yes_we_can');
757757
T (S('oneAtATime').underscore().s === 'one_at_a_time');
758+
T (S('oneAtATime AnotherWordAtATime').underscore().s === 'one_at_a_time_another_word_at_a_time');
758759
})
759760
})
760761

0 commit comments

Comments
 (0)