Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于图片正则表达式的错误的纠正 #22

Open
pendave opened this issue May 25, 2017 · 0 comments
Open

关于图片正则表达式的错误的纠正 #22

pendave opened this issue May 25, 2017 · 0 comments

Comments

@pendave
Copy link

pendave commented May 25, 2017

        def func(m):
            if not m.group(3).startswith("http"):
                rtn = m.group(1) + get_domain(url) + "/" + m.group(2) + m.group(3)
                #rtn = m.group(1) + domain + m.group(2) + m.group(3)
                return rtn
            else:
                return m.group(1) + m.group(2) + m.group(3)
        
        html = re.compile(pattern).sub(func, html)

我发现里面有问题,于是修改为

qq 20170526000446

大家可以看下 https://regex101.com/ 的测试效果
m.group(2) 才是匹配那个网址哦
qq 20170526000553
所以并不是错误的 m.group(3) 那个只是匹配到

而我看不懂那个正侧替换,查参考资料官方是
re.sub(pattern, repl, string, count=0, flags=0)

repl是字符串 或者 函数

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant