D
D
darzet2011-09-02 09:52:05
Regular Expressions
darzet, 2011-09-02 09:52:05

regexp question

I have a large number of paragraphs starting with the same headings.
For example

Gen\r\n
text
Gen\r\n
text
Gen\r\n
text
Gen\r\n
text

I want to make sure that only the first one remains. Gen

\r\n
text
text
text
text

Answer the question

In order to leave comments, you need to log in

3 answer(s)
P
pratamishus, 2011-09-02
@pratamishus

so if they are the same, regular expressions are not needed. You can just replay. for example
$title='Gen\r\n';
$text='Gen\r\n
text
Gen\r\n
text
Gen\r\n
text
Gen\r\n
text';
echo $title.str_replace($title, '', $text);

A
Alexander Keith, 2011-09-02
@tenbits

Delete every second line after the first:

Regex.Replace(text, "(?<=\r\n)(.+\r\n)(.+)", "$1")

U
UseRifle, 2011-09-03
@UseRifle

We enter the text into the array by paragraphs, run through the odd elements, if the element is equal to the previous odd one, we delete it. Then again we glue the array into a string.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question