Hi
I am trying to match all white spaces in a sentence, except for those after either a match on a particular word, or that particular word followed by another particular word.
I'm trying to use either lookahead or lookbehind. I can match the space immediately preceding the particular word, but not all the other spaces in the sentence.
Examples of the two sentences are (spaces to be matched are noted by { }; spaces not to be matched are noted by [ ] ):
I am using:
but this lookahead pattern matches only the space preceding 'toy'.
The two words are 'toy' and 'soldier'. 'toy' will always be present; if 'toy soldier' is present, 'soldier' will always follow 'toy', and 'soldier' will never appear by itself.
Any help greatly appreciated.
Cheers
pvr928
I am trying to match all white spaces in a sentence, except for those after either a match on a particular word, or that particular word followed by another particular word.
I'm trying to use either lookahead or lookbehind. I can match the space immediately preceding the particular word, but not all the other spaces in the sentence.
Examples of the two sentences are (spaces to be matched are noted by { }; spaces not to be matched are noted by [ ] ):
Hello{ }there{ }where{ }is{ }my{ }toy[ ]today{ }Daddy
Hello{ }there{ }where{ }is{ }my{ }toy[ ]soldier[ ]today{ }Daddy
I am using:
Code:
(?=\s).(\btoy\b|\btoy soldier\b)
but this lookahead pattern matches only the space preceding 'toy'.
The two words are 'toy' and 'soldier'. 'toy' will always be present; if 'toy soldier' is present, 'soldier' will always follow 'toy', and 'soldier' will never appear by itself.
Any help greatly appreciated.
Cheers
pvr928
Last edited: