How to find a number NOT preceding a specific end tag or being found within two specific tags?

How to find a number NOT preceding a specific end tag or being found within two specific tags?

81
Advanced UserAdvanced User
81

    Jan 07, 2017#1

    I'm looking to search for all \(\d+\) expressions in a file which satisfy the below conditions:

    1. The expression "\(\d+\)" should not be immediately followed by the string "</xref>"
    2. The search should avoid any/all expression "\(\d+\)" if that expression is inside tags "<inline>....</inline>" and "<disp>...</disp>"

    sample text:(just random gibberish text)

    I <xref rid="eqn1">(1)</xref> dsf dsf fd (6) dfd dsf dfds sdfds dsfds
    (16) to dsfds <inline>df fds (10) dsf</inline> fsdf <disp>adf dsf df (3)fa</disp>
    lp fds f dsf sfds <inline>df fds (5)</inline>

    The search pattern will only find the red colored expressions in the above sample.
    \(\d+\)(?!</xref>) only satisfies the 1st condition and I cannot figure out how to add condition 2 into the mix(if possible at all)

    Can anyone help :|

    18672
    MasterMaster
    18672

      Jan 12, 2017#2

      Hi,

      I suppose that the 2nd condition is not met for nested tags (e.g. (10) in <inline>df fds <value>(10)</value> dsf</inline> should be find).
      I also suppose that check for closing tags is enough (opening tag has to be there in the valid code, hasn't it?)
      Then you could try this simple pattern:

      \(\d+\)(?!</xref>)(?![^<]*</(inline|disp)>)

      BR, Fleggy

      81
      Advanced UserAdvanced User
      81

        Jan 14, 2017#3

        Thanks fleggy. It works fine as of now. :mrgreen: