I’m horrible at RegEx and I need a regex to test if a certain string ends a certain way. For example, if the RegEx tests for ending with foo, “somestringfoo” -> True and “someotherFoostring” -> False. It needs to be case sensitive and work with alphanumeric and underscore. Here is what I’ve got, but I can’t get it to work:
var test = RegExp.test('/foo$/');
testis a method of the regexp object, so it would be/foo$/.test(someString)ornew Regexp("foo$").test(someString).However, testing a string for ending with a certain substring does not need regular expressions, see endsWith in JavaScript.