Loading ...
Sorry, an error occurred while loading the content.

22379Re: [NTB] Regular Expression: find between two words

Expand Messages
  • Eb
    Feb 23, 2012
    • 0 Attachment

      I think you probably just want the text between the two words. That would require a search phrase like:

      "(?<=Word1 )[^\R]*(?= Word2)"

      In the search menu, you will not need the quotes.

      This expression is one of the most useful ways to use regular expressions, so I added a bit of explanation below (note the order of the explanations is different from the order of the expressions):

      1. "(?<=Word1 )" finds this word (and a following space) as a LEFT anchor (<=) to the desired text, but does not include it in the match.

      3. "(?= Word2)" is the RIGHT anchor to the target text, and will not be included. See NoteTab's Help on regular expressions, and look for "Assertions".

      2. "[^\R]*" between the two anchors searches for any and all character other than a newline sequence. Without the neline exclusion, the search may find Word2 on some other line, and include everything up to THAT Word2, instead of the one on the line you're interested in.

      If you're going to learn anything about regular expressions, THIS is the one I would recommend.



      --- In notetab@yahoogroups.com, Don <don@...> wrote:
      > Hit find and then tick the regular expression box and then search for this:
      > Word1 (.*) Word2
      > That will find it and assign it to a temporary spot where if you were
      > using a replace you could insert it with $1.
      > On 2/23/2012 12:42 PM, book7reader wrote:
      > > Hello,
      > >
      > > I want to find any text or numbers that exist between two words (the two words are always present in the line but what is between the changes.) For example in the line...:
      > >
      > > "Word1 some text or numbers-2 here Word2"
      > >
      > > ...I want to find:
      > >
      > > " some text or numbers-2 here " portion of the text based on the "Word1" and "Word2" delimiters.
      > >
      > > Thanks for your help,
      > >
      > > James
    • Show all 15 messages in this topic