Regex - find lines starting with 2 dashes containing single speech mark

Viewed 38

Starting with this sample text:

-- Search for relevant Title, second half of the screen, under "Context Field Values" lists the main parts of the Flexfield
-- This lists the bits users see in Core Applications when they click into the DFF plus shows if there is a LOV linked to the field
-- It's a test
-- So is this

      SELECT fat.application_name
           , fdfv.title
           , fdfv.application_table_name

How can I use a RegEx in Notepad++ to find any lines starting with -- and containing a single speech mark '?, so that only this line is returned:

-- It's a test

I tried a silly amount of things, such as:

  • [^--']
  • [^--*']
  • [*--*']
  • --[']
  • [--][']
  • [']
  • ^--[']
  • ^--*\'*
  • ^--*'*

But as you can see, I'm not too clever!

2 Answers

You may use this regex to match a line starting with -- containing only a single ':

^\s*--[^'\r\n]*'[^'\r\n]*$

Make sure to keep MULTILINE mode on since we are using anchor ^.

RegEx Demo

RegEx Breakup:

  • ^: Start
  • \s*: Match 0 or more whitespaces
  • --: Match --
  • [^'\r\n]*: Match 0 or more of any char that is not ' and not a line break
  • ': Match a '
  • [^'\r\n]*: Match 0 or more of any char that is not ' and not a line break
  • $: End
  • Ctrl+F
  • Find what: ^--.*'.*$
  • TICK Wrap around
  • SELECT Regular expression
  • UNTICK . matches newline
  • Find All in Current Document

Explanation:

^       # beginning of line
    --      # 2 dashes
    .*      # 0 or more any character but newline
    '       # a single quote
    .*      # 0 or more any character but newline
$       # end of line

Screenshot:

enter image description here

Related