0

Let's say there's a textarea text with following content:

On date at 3:16 PM, Sir Voldemort wrote:

> Sweet Harry!
> Let's see what's gonna happen.
>
>
> On date at 3:11 PM, wrote:
>
>> Awesome!
>>
>>
>> --
>> Random: string or sentence here, it doesn't matter
>> Another random line with e.g. a URL: http://www.jkrowling.com/
>>
>
>
>
> --
> **********************************************
>   ABCABCCAB
> **********************************************
>

Quote
“Efe iska?” 

--
Random2-1
Random2-2

**********************************************
  ABCABCABC
**********************************************

Now if there occurs a line with just two dashes -- (and none, one or more > in front) in it, this line and the following two lines should get deleted.

Like that:

On date at 3:16 PM, Sir Voldemort wrote:

> Sweet Harry!
> Let's see what's gonna happen.
>
>
> On date at 3:11 PM, wrote:
>
>> Awesome!
>>
>>
>>
>
>
>
> **********************************************
>

Quote
“Efe iska?” 


**********************************************
  ABCABCABC
**********************************************

I already started with the following code to detect the previous line of -- to start a another substr but there is more sure a way more simple regexp solution for it?

var msg = document.getElementById('msg'); // wrapped textarea around the text with ID msg
msg.value = msg.value.substr(0, msg.value.substr(0, msg.value.match('--\n').index).lastIndexOf('\n'))
2
  • Why are not the lines > --, > ************* and > ABCABCCAB being deleted? They follow the pattern you indicate. Commented Oct 5, 2014 at 11:43
  • Yes, sorry you are right, I forgot to remove them as well. Commented Oct 6, 2014 at 2:13

1 Answer 1

1

This should work.

str.replace(/\n>*\s*--\n.*\n.*/g, '')

Results in:

On date at 3:16 PM, Sir Voldemort wrote:

> Sweet Harry!
> Let's see what's gonna happen.
>
>
> On date at 3:11 PM, wrote:
>
>> Awesome!
>>
>>
>>
>
>
>
> **********************************************
>

Quote
“Efe iska?” 

**********************************************
  ABCABCABC
**********************************************
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.