skip to Main Content

I want to select text till the linebreak (or any other) is repeated twice

I tried to stop selection with [^n]*?

However, I like to do something that can select will two (or more) consecutive linebreaks are encountered

used regex in JS

/^(?!#{1,6}s|*s|d+.s|!|[|>+s+|-||)([^n]*?)n{1,}$/gmi

dummy text


select this First in a single line



select this second one line

select these multiline paragraph
including this I want to select these 3 line in one paragraph
However only last line is selected in a group I am using [^n]*?








# do not select anything below
> one line

> multiline paragraph
> secondline
> single



>> one line

>> multiline paragraph
>> secondline
>> single





# heading

---

|S.No|name|
|:---|---|---|
|1|prateek|

## headgin

* list

1. list

11. asdfli

![asdf](image)

[asd](heading)







demo

https://regex101.com/r/s7nKFq/1

2

Answers


  1. If you are parsing Markdown, please consider using a parser instead of regex. The following regex should only be used in case you have no other choice as it cannot guarantee a correct match for every possible situation.

    ^             # At the beginning of line, match
    (?!d+.)     #                        and not a number followed by a dot,
    [^[!|#>n*-]  # not one of '[!|#>n*-'                                     followed by
    .+?           # one or more characters, as few as possible,
    (?=(.)1)     # all of which is succeeded by two repeated characters.
    

    Try it on regex101.com.

    Login or Signup to reply.
  2. ^(?!s*$|#{1,6}s|*s|d+.s|!|[|>+|-||)([sS]*?)n{2,}

    https://regex101.com/r/nrssCf/1

    explain

    s*$ match an empty line.

    n{2,} two or more linebreak.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search