My problem seems trivial, yet I can't quite seem to grasp what I am doing wrong. I am trying to detect the end of sentences by using a regular expression to find periods. The thing is, I only want say, periods that come after a word with more than 2 letters in it, that way I can avoid a false positive of "St. Nicholas."
My current expression is:
/\w{3,}\./g
However, this seems to select the whole word, rather than just the period. What am I doing wrong?
EDIT:
I am expecting
"St. Kitts is really cool. Like seriously, sweet."
To return the period after both "cool" and "sweet", but not after "St."
EDIT 2:
This is in Javascript, so a normal lookbehind of (?<=text) will not work
You can use groups:
var myRegexp = \w{3,}(\.);
var match = myRegexp.exec(your string);
alert(match[1]); // Here you should have captured the period
And if there is more than one period:
match = myRegexp.exec(myString);
while (match != null) {
// matched period: match[1]
match = myRegexp.exec(myString);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.