开发者

How to find First & Last Line using Regex?

    2011-08-31   62,756 1400177600.pptx
    2011-09-01  129,988 1403639000.pptx
    2011-09-05  364,884 4003557200.pptx
    2011-09-05  88,484 4400167700.pptx
    2011-09-01  37,908 4400169200.pptx

above is original text.. i want to covert this

    <contents>
    2011-08-31   62,756 1400177600.pptx
    2011-09-01  129,988 1403639000.pptx
    2011-09-05  364,884 4003557200.pptx
    2011-09-05  88,484 4400167700.pptx
    2011-09-01  37,908 4400169200.pptx
    </contents>

I need to find first 开发者_StackOverflow社区& last line using Regex on Notepad++

How can I find first and last line ?


Not sure if this works, but I used this in Textmate:

^(?:(?<![\f\n\r])(?:.*))(?=[\f\n\r])|^.*(?![\f\n\r])$

The first part,

^(?:(?<![\f\n\r])(?:.*))(?=[\f\n\r])

finds the first line. Not sure about Notepad++, but (annoyingly) Textmate matches ^ to any start of line. So I had to check for the text (.*) that is followed by a form feed, newline or return ([\f\n\r]), and is not preceded by the same.

The second part,

^.*(?![\f\n\r])$

was easier. It just finds a start of a line (^) with the text (.*) that is not followed by a end of line.

EDIT: after re-reading OP's post I get that it should have the beginning tag and closing tag. To do that, you could use the first part of the expression for the beginning tag and the last expression for the end tag.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜