正则表达式之间,从上到特定的结束 [英] Regex between, from the last to specific end

查看:118
本文介绍了正则表达式之间,从上到特定的结束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天,我的愿望是把文本形式的字符串。
此字符串必须是,最后一个斜线 .partX.rar .rar程序

Today my wish is to take text form the string. This string must be, between last slash and .partX.rar or .rar

首先,我试图找到该字,然后开始的边缘结束。之后我得到了两个因素我合并他们,但我得到空的结果。

First I tried to find edge's end of the word and then the beginning. After I get that two elements I merged them but I got empty results.

字符串:

http://hosting.xyz/1234/15-game.part4.rar.html

http://hosting.xyz/1234/16-game.rar.html

正则表达式:

开始:(([^ /] *)$) - 从去年 /

Begin:(([^/]*)$) - start from last /

结束:(*(=部分[0-9] + RAR | .rar程序)。?。) .partX停止.rar程序 .rar程序

正如你所看到的,如果我合并我的代码不会得到任何结果。
更重要的是,结束选择我的只有.partX而不是.partX.rar的

As you see, if I merge that codes I won't get any result. What is more, "end" select me only .partX instead of .partX.rar

所有我想要的是:
15 game.part4.rar 16 game.rar

我的尝试:

(([^/]*)$)(.*(?=.part[0-9]+.rar|.rar))

(([^/]*)$)

(.*(?=.part[0-9]+.rar|.rar))

我也试过

/[a-zA-Z0-9]+

但我不知道怎么的符号选择。这可能是最简单的方法。但是,这仅选择字母和数字,不能 - _
如果我可以选择的符号。

but I do not know how select symbols.. This could be the easiest way. But this select only letters and numbers, not - or _. If I could select symbols..

推荐答案

我不是一个C#编码器等都不能写满代码这里,但我认为你需要支持负向前看这里是这样的:

I'm not a C# coder so can't write full code here but I think you'll need support of negative lookahead here like this:

new Regex("/(?!.*/)(.+?)\.html$");



匹配的组#1将您的字符串即16 game.rar 15 game.part4.rar

这篇关于正则表达式之间,从上到特定的结束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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