Skip to main content
gert verrept
Inspiring
May 29, 2017
Answered

find between brackets

  • May 29, 2017
  • 2 replies
  • 3487 views

FIND

\(([^()]|(?R))*\)

CHANGE

italic (char style)

gives

(sunt quaepta (tiorepta perovit aliquibus) dem)

The grep above finds what is between brackets, but I want it to find the whole text between the exterior brackets, but without the brackets.

getting it so:

(sunt quaepta (tiorepta perovit aliquibus) dem)

    This topic has been closed for replies.
    Correct answer Obi-wan Kenobi

    Hi,

    Jongware's way works only in one case: double-parenthesis between parenthesis.

    Dhafir's one only catches the text not the parenthesis.

    This one uses the Grep recursive code Gert indicates us [ ]. To do what he wants to get [in all situations], just play 2 regex [+ 3rd optional]:

    (^/)

    2 replies

    Inspiring
    May 29, 2017

    Hi gert verrept,

    Try this by one click:

    (?<=\))[^\(]+?(?=\))|(?<=\()[^\(]+?(?=\))|(?<=\()[^\(]+?(?=\()

    Jongware
    Community Expert
    Community Expert
    May 29, 2017

    This will do the job, but extremely literally: it will only and exclusively match the outer parenthesized phrase (sans parens) when there is a single parenthesized expression within.

    (?<=\()[^()\r]*\([^()\r]*\)[^()\r]*(?=\))

    Close enough? I don't think it can be adjusted to account for "either/or". In that case you're probably better off just replacing all of the text with italics, and then selectively remove it from just the outermost parentheses.

    Obi-wan Kenobi
    Obi-wan KenobiCorrect answer
    Legend
    May 29, 2017

    Hi,

    Jongware's way works only in one case: double-parenthesis between parenthesis.

    Dhafir's one only catches the text not the parenthesis.

    This one uses the Grep recursive code Gert indicates us [ ]. To do what he wants to get [in all situations], just play 2 regex [+ 3rd optional]:

    (^/)