What Regex would capture everything from ' mark to the end of a line?

前端 未结 7 1509
南方客
南方客 2020-12-12 16:32

I have a text file that denotes remarks with a single \'.

Some lines have two quotes but I need to get everything from the first instance of a \

7条回答
  •  失恋的感觉
    2020-12-12 17:19

    This will capture everything up to the ' in backreference 1 - and everything after the ' in backreference 2. You may need to escape the apostrophes though depending on language (\')

    /^([^']*)'?(.*)$/
    

    Quick modification: if the line doesn't have an ' - backreference 1 should still catch the whole line.

    ^ - start of string
    ([^']*) - capture any number of not ' characters
    '? - match the ' 0 or 1 time
    (.*) - capture any number of characters
    $ - end of string
    

提交回复
热议问题