Use regex to find specific string not in html tag

后端 未结 8 1112
温柔的废话
温柔的废话 2021-02-05 08:53

I\'m having some difficulty with a specific Regex I\'m trying to use. I\'m searching for every occurrence of a string (for my purposes, I\'ll say it\'s \"mystring\") i

8条回答
  •  独厮守ぢ
    2021-02-05 09:07

    When your regex processor doesn't support variable length look behind, try this:

    (<.+?>[^<>]*?)(_mystring_)([^<>]*?<.+?>)
    

    Preserve capture groups 1 and 3 and replace capture group 2:

    For example, in Eclipse, find:

    (<.+?>[^<>]*?)(_mystring_)([^<>]*?<.+?>)
    

    and replace with:

    $1_newString_$3
    

    (Other regex processors might use a different capture group syntax, such as \1)

提交回复
热议问题