Lua frontier pattern match (whole word search)

后端 未结 1 1710
鱼传尺愫
鱼传尺愫 2021-01-22 02:08

can someone help me with this please:

s_test = \"this is a test string this is a test string \"

function String.Wholefind(Search_string, Word)
 _, F_result = st         


        
相关标签:
1条回答
  • 2021-01-22 02:52

    Your pattern doesn't match because you are trying to do the impossible.

    After including your variable value, the pattern looks like this: %f[%a]123test%f[%A]. Which means:

    1. %f[%a] - find a transition from a non letter to a letter
    2. 123 - find 123 at the position after transition from a non letter to a letter. This itself is a logical impossibility as you can't match a transition to a letter when a non-letter follows it.

    Your pattern (as written) will not work for any word that starts or ends with a non-letter.

    If you need to search for fragments that include letters and numbers, then your pattern needs to be changed to something like '%f[%S]'..Word..'%f[%s]'.

    0 讨论(0)
提交回复
热议问题