正则表达式 - 赛最后一场次数 [英] Regex - Match Last Occurance

查看:178
本文介绍了正则表达式 - 赛最后一场次数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文本文件的全名,我想通过正则表达式匹配他们所有。

I have a text file full of names, I want to match them all via Regex.

每个名字以下列文本结束

Each name ends with the following text: fsa fwb fcc, eg:

">Dave Smith\u0012\/a>\u0012\/div>\u0012div class=\"fsa fwb fcc

我想用下面的EX pression相匹配的名称:

I want to use the following expression to match the names:

""">.+?""fsa fwb fcc"

AKA匹配所有文字> FSA FWB FCC ,然后我就可以解析多余的匹配自己。

AKA match all text from "> up to fsa fwb fcc, I can then parse the excess matched myself.

然而,随着>出现在整个文件中,它从早得多匹配的。我一直在想如何从东西最后的次数匹配,在这种情况下,> ,达END指定。

However as "> occurs throughout the file, it starts matching from much earlier. I have always wondered how to match from the LAST occurance of something, in this case, ">, up to the end specified.

感谢所有, 斯坦。

推荐答案

它看起来像你结束的字符串字面 FSA FWB FCC ,而你是最后一个<$ C $后直接兴趣开始的子字符串的开始C>&GT; 结束字符串之前

Description

It looks like you're ending string is literally fsa fwb fcc, and the beginning of the substring you're interested in starts directly after the last "> before the end string.

这EX pression将:

This expression will:

  • 找到最近的&GT之间的子字符串; 和下 FSA FWB FCC

&GT;(?(:(?!&GT;))*)FSA \ sfwb \ SFCC

现场演示

示例文本

">sometext">A Dave Smith\u0012\/a>\u0012\/div>\u0012div class=\"fsa fwb fcc
">sometext">B Dave Smith\u0012\/a>\u0012\/div>\u0012div class=\"fsa fwb fcc
">sometext">C Dave Smith\u0012\/a>\u0012\/div>\u0012div class=\"fsa fwb fcc

结果:

[0][0] = ">A Dave Smith\u0012\/a>\u0012\/div>\u0012div class=\"fsa fwb fcc
[0][1] = A Dave Smith\u0012\/a>\u0012\/div>\u0012div class=\"

[1][0] = ">B Dave Smith\u0012\/a>\u0012\/div>\u0012div class=\"fsa fwb fcc
[1][1] = B Dave Smith\u0012\/a>\u0012\/div>\u0012div class=\"

[2][0] = ">C Dave Smith\u0012\/a>\u0012\/div>\u0012div class=\"fsa fwb fcc
[2][1] = C Dave Smith\u0012\/a>\u0012\/div>\u0012div class=\"

如果你想更进一步,从最后只能捕获&GT; 通过对 \ u0012 前在 FSA FWB FCC ...即实际的名称,而不是标记文本,然后看看这个EX pression

Or

If you want to go further and only capture from the last "> through to the \u0012 before the fsa fwb fcc ... i.e. the actual name and not the markup text, then have a look at this expression

&GT;(?(:(?!&GT;)。)*)\\ u0012(:(?!&GT;?))* FSA \ sfwb \ SFCC <。 / code>

">((?:(?!">).)*?)\\u0012(?:(?!">).)*fsa\sfwb\sfcc

现场演示

示例文本

">sometext">A Dave Smith\u0012\/a>\u0012\/div>\u0012div class=\"fsa fwb fcc
">sometext">B Dave Smith\u0012\/a>\u0012\/div>\u0012div class=\"fsa fwb fcc
">sometext">C Dave Smith\u0012\/a>\u0012\/div>\u0012div class=\"fsa fwb fcc

结果

[0][0] = ">A Dave Smith\u0012\/a>\u0012\/div>\u0012div class=\"fsa fwb fcc
[0][1] = A Dave Smith

[1][0] = ">B Dave Smith\u0012\/a>\u0012\/div>\u0012div class=\"fsa fwb fcc
[1][1] = B Dave Smith

[2][0] = ">C Dave Smith\u0012\/a>\u0012\/div>\u0012div class=\"fsa fwb fcc
[2][1] = C Dave Smith

这篇关于正则表达式 - 赛最后一场次数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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