V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
caola
V2EX  ›  Lua

Lua 怎么实现 php strstr() 函数的功能

  •  
  •   caola · Aug 19, 2016 · 10267 views
    This topic created in 3539 days ago, the information mentioned may be changed or developed.

    最近接触了下 openresty(lua),想弄点自己的功能,但遇到小问题:

    local myPosition = string.find(myStr, myValue) --查找字符所在位置 string.sub(myStr, myPosition) --取出找到的字符以及之后的字符串

    PS : myValue 可能是任何字符串(有可能是字母数特殊符号和中文的混合字符串), string.find 这函数没法直接查找,得要各种转义,非常蛋疼。

    想问一下还能有什么 lua 能高效的实现 php strstr() 功能的方法?

    3 replies    2025-01-07 15:34:58 +08:00
    esile
        1
    esile  
       Aug 20, 2016 via iPhone
    正则
    Lexo
        2
    Lexo  
       Apr 10, 2020
    string.find("Hello world","Hello",1,true)

    第一个参数是母字符串,第二个参数是子字符串,第三个是从第几位开始匹配,第四个设为 true,就可以开启仅字符串匹配,而不是用 Lua 正则匹配,无需转义
    wionch
        3
    wionch  
       Jan 7, 2025
    用 c 语言写个模块来实现。[狗头]
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3169 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 13:40 · PVG 21:40 · LAX 06:40 · JFK 09:40
    ♥ Do have faith in what you're doing.