• Login
Community
  • Login

Problem with regex

Scheduled Pinned Locked Moved General Discussion
2 Posts 2 Posters 198 Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K
    kanishknishar
    last edited by Nov 29, 2022, 4:46 AM

    This is my text:

    I. Allegro (in B-flat major and in sonata form)
    II. Tema con variazioni (Andante) (theme and 6 variations, where the theme and all the variations are in F major)
    III. Menuetto - Trio (in B-flat major and in ternary form, trio in G minor)
    IV. Adagio (in E-flat major and in sonata form)
    V. Menuetto - Trio (in B-flat major and in ternary form, trio in E-flat major)
    VI. Andante - Allegro molto (in B-flat major, beginning with an introductory instrumental recitative, and in sonata rondo form)
    

    I want to remove all the text that is in parentheses. I wrote a simple regex for it: https://regex101.com/r/z57nQC/1 and it works too (except the last) but when I try it on Notepad++ it finds no matches. What’s going on?

    T 1 Reply Last reply Nov 29, 2022, 5:26 AM Reply Quote 0
    • T
      Terry R @kanishknishar
      last edited by Terry R Nov 29, 2022, 5:29 AM Nov 29, 2022, 5:26 AM

      @kanishknishar said in Problem with regex:

      and it works too (except the last) but when I try it on Notepad++ it finds no matches. What’s going on?

      Your regex is looking ONLY for \n whereas normally you would use \r\n which refers to carriage return AND line feed, or \R which means any type of line ending, \n, \r or \r\n .\r\n is the normal line ending in a Windows TXT file.

      However the last line will not have these so I’d change your current \n for a $ which means end of line, just before the carriage return and line feed. By not selecting the actual line endings you don’t need to return it as a replacement.

      Terry

      PS you could even use this version of your regex if all the closing brackets finish the line

      1 Reply Last reply Reply Quote 3
      2 out of 2
      • First post
        2/2
        Last post
      The Community of users of the Notepad++ text editor.
      Powered by NodeBB | Contributors