javascript - Match single word, with possible punctuation or pluralization at end (Regex) -
i've been getting improve @ regex, i've come beyond i'm able do.
i want build function test (return true or false) test see if word found within string. wouldn't want have positive match if word found within of word. build in possibility of checking pluralization.
here examples of results i'd expect get:
word for: "bar"
"strings search in" //what should homecoming as
"foo bar" //true
"foo bar." //true
"foo bar!" //true (would true other punctuation before or after 'bar' too)
"foo bars." //true
"foo bares." //true (even though bares has different meaning bars, okay returning true since need check words pluralize "es" , wouldn't expect build regex know words pluralize "s" , "es")
"my name bart simpson" //false (bar part of "bart")
"bart simpson went bar." //true
i'll using javascript/jquery check matches
thanks much help!
var rgx = new regexp('\\b' + word + '(?:es|s)?\\b'); rgx.test(string);
this homecoming true
of strings specified in request. \b
represents "word boundary," believe character in \w
(including period , exclamation point) start or end of string.
javascript regex
No comments:
Post a Comment