Using "find" to search for words separated by several others

Feature requests, and in-depth discussions of features and the way Mellel works

Moderators: Eyal Redler, redlers, Ori Redler

Post Reply
eirikharris
Got the styles thing figured out
Posts: 7
Joined: Tue Jul 10, 2007 7:20 pm

Using "find" to search for words separated by several others

Post by eirikharris »

Does Mellel have the ability to find instances of two words when they are not adjacent to each other, but rather separated by other words?

What I would like to do is find every instance in which "word 1" is found in the same sentence as "word 2". I am imagining a command that tells mellel to find all instances where "word 1" is within, say 8 words of "word 2".

So, imagine that I want to find every instance in which the names "Bob" and "Cindy" occur in close proximity, but not when they occur alone. The command should allow me to find, for example, the following sentence: "Yesterday, Bob was walking down the street when he met Cindy," but exclude "Bob woke up late this morning and missed the bus."

If anyone can tell me if this is possible, I'd appreciate it - and please let me know if I'm being unclear!
rpcameron
Knows everything, can prove it
Posts: 980
Joined: Wed Oct 26, 2005 12:48 am
Location: IE, CA, USA

Re: Using "find" to search for words separated by several others

Post by rpcameron »

Yes, it is possible. Something maybe like:

Code: Select all

{Bob}{space}({characters w/o WS}{space})(1-8 times){Cindy}{characters}{period}
The challenge is in creating a regex that Mellel understands that will give you the intermediate words, but will restrict the search to within a sentence. I'm not certain how best to do it, but perhaps looking at some regex tutorials online might give some help. Then, the regex could be easily transformed into an expression that Mellel understands.

Hope this helps, or offers some suggestions. (A nested expression for the intermediate words might be necessary.)
— Robert Cameron
rpcameron
Knows everything, can prove it
Posts: 980
Joined: Wed Oct 26, 2005 12:48 am
Location: IE, CA, USA

Re: Using "find" to search for words separated by several others

Post by rpcameron »

I just looked at Mellel's Find dialog, and came up with something that might work:

Code: Select all

Bob{Word boundary}{Group: {Any character}(Once or more, not greedy){Word boundary}}(Repetition: Min, 1; Max, 8)Cindy
Basically, the steps to create this are:
  • Bob
  • Insert element: Word boundary
  • Insert element: Any character; Repetition: Once or more
  • Insert element: Word boundary
  • Group items: Any character + Word boundary; Repetition: Range, Min: <How close can they occur>, Max: <How far apart is too far>
  • Cindy
Hopefully that makes some sense. I haven't done any testing on this to see if it will give you the desired results, but it should serve as a jumping off point. The Min and Max values relate to the group of characters followed by a word boundary that precede "Cindy", which basically is the number of words in between "Bob" and "Cindy". If you wanted to ensure there were at least 3 words between them, but no more than 8, then Min and Max would be 3 and 8, respectively.
— Robert Cameron
eirikharris
Got the styles thing figured out
Posts: 7
Joined: Tue Jul 10, 2007 7:20 pm

Re: Using "find" to search for words separated by several others

Post by eirikharris »

Thanks a lot, Patrick, I really appreciate it! I'll start playing around with it and see how it goes.
Post Reply