How to represent reluctant quantifier in regex replace to replace the smallest match

leoking
2014-04-09
2014-04-10
  • leoking
    leoking
    2014-04-09

    I using regex search to replace the following string:

    \new{}\new{test1}\new{test2}
    

    with

    test1test2
    

    I using regex replace with \new{(.*)} to find and \1 to replace.

    however the search always match the whole line of my original string and the replace reuslt is:

    }\new{test1}\new{test2
    

    far from what I need.

    In regex expression in Java, you can use a ? after a quantifier makes it a reluctant quantifier. It then tries to find the smallest match. So in java, my search regex expression would be

    \\new\{(.*?)\}
    

    I need the corresponding regex search string in TeXStudio to do the smallest match.

    Thanks.

     
    Last edit: leoking 2014-04-09
  • reliak
    reliak
    2014-04-10

    Hi,

    that's the pattern you're looking for:
    \\new\{([^}]*)\}

     
    Last edit: reliak 2014-04-10