重写正则表达式而不是否定 [英] Rewrite regex without negation

查看:129
本文介绍了重写正则表达式而不是否定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


$ b

https::\ / \ /(()由于我使用的是golang / regexp lib,因此我们可以使用golang / regexp lib,我无法使用它,因为我的否定(?!..



我想要什么要处理它,就是选择所有从http / https最后一次出现的文本直到结束。

  sometextsometexhttp:/ /websites.com/path/subpath/#query1sometexthttp://websites.com/path/subpath/#query2 

=>输出: http://websites.com/path/subpath/#query2

任何人都可以帮助我解决问题,我花了好几个小时尝试不同的方式来重现相同的结果,但没有成功。



  https:

:] * $

Regex住在这里。


I have wrote this regex to help me extract some links from some text files:

https?:\/\/(?:.(?!https?:\/\/))+$

Because I am using golang/regexp lib, I'm not able to use it, due to my negation (?!..

What I would like to do with it, is to select all the text from the last occurance of http/https till the end.

sometextsometexhttp://websites.com/path/subpath/#query1sometexthttp://websites.com/path/subpath/#query2

=> Output: http://websites.com/path/subpath/#query2

Can anyone help me with a solution, I've spent several hours trying different ways of reproducing the same result with no success.

解决方案

Try this regex:

https?:[^:]*$

Regex live here.

这篇关于重写正则表达式而不是否定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆