简体   繁体   English

正则表达式得到模式的最后一句话

[英]Regex get last word of pattern

i have this string 我有这串

<p>&nbsp;&nbsp;&nbsp;&nbsp;this is some text</p>

&nbsp; can be any number of times 可以任意次数

to match i am using regex (?<=<p.*?>*&nbsp;)(.*)(?=</p>) 匹配我正在使用正则表达式(?<=<p.*?>*&nbsp;)(.*)(?=</p>)

but i am getting &nbsp;&nbsp;&nbsp;this is some text as output 但是我得到的&nbsp;&nbsp;&nbsp;this is some text作为输出

How to get this is some text 如何获得this is some text

EDIT 编辑

i am sorry my string is <p class='randomstring'>a)&nbsp;&nbsp;&nbsp;&nbsp;this is some text</p> in place of a) there is digit some times. 很抱歉,我的字符串是<p class='randomstring'>a)&nbsp;&nbsp;&nbsp;&nbsp;this is some text</p>代替a) <p class='randomstring'>a)&nbsp;&nbsp;&nbsp;&nbsp;this is some text</p> ,而不是a)有时会有数字。

You can use this regex: 您可以使用此正则表达式:

(?<=<p[^>]*>)(?:&nbsp;)+(.*)(?=</p>)

And grab the captured group #1 for you match, that will be: 并抓住与您匹配的捕获的第一组 ,那就是:

this is some text

EDIT: Based on your edited question try this regex: 编辑:根据您编辑的问题,请尝试此正则表达式:

(?<=<p[^>]*>)[^)]*\) *(?:&nbsp;)+(.*)(?=</p>)

You could use the below regex which uses variable length positive lookbehind. 您可以使用下面的正则表达式,该正则表达式使用可变长度正向后看。

(?<=<p[^>]*>(?:&nbsp;)+)\b.*?(?=</p>)

This should match only the string this is some text 这应该只匹配字符串, this is some text

Update: 更新:

(?<=<p[^>]*>\w*\)(?:&nbsp;)+)\b.*?(?=</p>)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM