Tuesday, 15 February 2011

regex - Regular expressions : is it possible to take all words in a text in pairs? -



regex - Regular expressions : is it possible to take all words in a text in pairs? -

i using pcre find pairs of words in phrase, eg. phrase "the quick brownish fox jumped on lazy dog." should produce

the quick quick brownish brown fox fox jumped jumped on ... ... lazy dog

i using function findandconsume() consumes both words , getting half results !

the quick brownish fox jumped on ... ... lazy

so trying find if there way retrieve pairs of words.

regular expressions not find overlapping matches. want do, suggest first split text words, utilize normal loop extract items neighbours.

alternately, can set sec word in regular look in lookahead, , capture it: (\w+)(?=\w+(\w+)\b) - create sure captures, not matches (since matches still include first word).

regex pcre

No comments:

Post a Comment