Reputation: 5372
Is there an easy way to detect a phrasal template in a block of text?
For example, given the text:
Not sure how to approach this. It's very difficult, and by difficult I mean I don't know how to do it. But maybe it's obvious for someone else?
And the template:
[x], and by [x] I mean [Y]
Would result in a match.
I would assume that regex of some description would be the best bet, although I don't know if such a thing is possible with regex.
Bonus: what would be the most computationally efficient approach, if trying to match many templates in succession?
Edit: Just to clarify, I just need an exact match. For example the above template would not have to match the following:
apple, and by apple I do mean pear
Upvotes: 1
Views: 131
Reputation: 10789
If you need matching by regexp you can use this one:
(\w+), and by \1 I mean \w+
apple, and by apple I mean pineapple -> match
apple, and by apple I do mean pear -> not match
(\w+) - matches 1 word and save it to first group
\1 - word from first group
\w+ - match second word
Play with regexps more on http://regexpal.com/
But if you really need matching with lot of patterns you need define all patterns that you need and build own finite state machine
Upvotes: 1