简体   繁体   English

如何使用正则表达式提取子字符串?

[英]How to use a regular expression to extract a substring?

so im trying to figure out regular expressions in Flex, but cant for the life of me figure out how to do the following. 所以我试图找出Flex中的正则表达式,但是我一生都无法找出如何执行以下操作。 From the sample below, i need to extract out only "Mike_Mercury". 从下面的示例中,我只需要提取“ Mike_Mercury”。

So i have to somehow strip out everything around it with RegExp, or whatever's best. 因此,我必须以某种方式用RegExp去除周围的所有东西,或者最好的东西。 Also, I would need it to work with other samples as well. 另外,我还需要它与其他示例一起使用。 Im getting this from the reddit api , so id have to extract that same section from a whole bunch of these. 我从reddit api获得了这个信息,所以id必须从一大堆中提取相同的部分。 Thanks! 谢谢!

 <table>
            <tr>
                <td>
                    <a href="http://www.reddit.com/r/atheism/comments/q2sfe/barack_obamas_insightful_words_on_abortion/">
                        <img src="http://d.thumbs.redditmedia.com/9StfiHi7hEbf8v73.jpg" alt="Barack Obama's insightful words on abortion"
                            title="Barack Obama's insightful words on abortion" /></a>
                </td>
                <td>
                    submitted by <a href="http://www.reddit.com/user/Mike_Mercury">Mike_Mercury </a>
                    to <a href="http://www.reddit.com/r/atheism/">atheism</a>
                    <br />
                    <a href="http://imgur.com/lKFYr">[link]</a> <a href="http://www.reddit.com/r/atheism/comments/q2sfe/barack_obamas_insightful_words_on_abortion/">
                        [1722 comments]</a>
                </td>
            </tr>
        </table>

试试这个正则表达式:

submitted by <a href=".*?">(.*?)</a>

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

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