jweinst1
11/6/2015 - 5:30 AM

javascript regex for words and suffixes

javascript regex for words and suffixes

// matching suffixs and prefixes in js

function match_ve (string) {
    return string.match(/[a-z]*ve/g);
}
//matches a prefix, therm
function match_therm (string) {
    return string.match(/therm[a-z]*/g);
}
/*   match_therm("i need a thermometer today")
=> [ 'thermometer' ]
   */

var matcher = function () {
};

matcher.prototype.match_alt = function (string) {
        return string.match(/alt[a-z]+/g);
    };
matcher.prototype.prefix_alt = function (string) {
    return string.match(/([a-z]+)(?=alt)/g);
};