Word Pair or Word Triplet Extracts
Posted: Tue Oct 14, 2003 12:38 am
I am trying to write a Regex expression to match all adjacent word pairs and triplets for any given string of words. For example, the sentence:
"registrars have been contracted to perform services at very low prices" would produce the following word pairs:
"registrars have", "have been", "been contracted", "contracted to", "to perform", "perform services", etc.
or the following triplets:
"registrars have been", "have been contracted", "been contracted to", "contracted to perform", etc.
I can extract the first two words from a search string, such as:
(.*Subject: )(\w* ){2} filter out the first back reference, but I am stuck writing an expression that will pull all of the concurrent word pairs from a string.
Any suggestions how this can be done with regex alone?
Thanks,
Jeff
"registrars have been contracted to perform services at very low prices" would produce the following word pairs:
"registrars have", "have been", "been contracted", "contracted to", "to perform", "perform services", etc.
or the following triplets:
"registrars have been", "have been contracted", "been contracted to", "contracted to perform", etc.
I can extract the first two words from a search string, such as:
(.*Subject: )(\w* ){2} filter out the first back reference, but I am stuck writing an expression that will pull all of the concurrent word pairs from a string.
Any suggestions how this can be done with regex alone?
Thanks,
Jeff