regex - Extracting first sentence from a paragraph -
is there way can extract first sentence paragraph. can regex used here. if yes how?
say example paragraph below has 2 sentences, , need first sentence:
"the japanese loan available @ 0.1% interest rate on oct. 25 , india able repay in 50 years. repayment begin 15 years after loan received."
my desired output: japanese loan available @ 0.1% interest rate on oct. 25 , india able repay in 50 years.
how can that? there vba code using regex can used here?
regards karan
regular expressions can used. following uses simple typical definition of "end of sentence": .
, !
or ?
followed either 1) @ least 1 space capital letter, or 2) end of text.
public function thefirstsentence(byref text string) string new vbscript_regexp_55.regexp .pattern = ".*?[.!?](?= +[a-z]|$)" if .test(text) thefirstsentence = .execute(text)(0).value else thefirstsentence = vbnullstring end if end end function
just remember enable reference microsoft vbscript regular expressions 5.5
.
Comments
Post a Comment