Search code examples
regexselectparagraphnegative-lookbehind

How can I exclude the first character of a paragraph from the selection?


This selects the content of a paragraph.

^(.*)$

This additionally selects the selected number of beginning characters of a paragraph, but does not exclude them.

^[^.*{1}](.*)$

Solution

  • Depending on the type of regex you're using, you could use \K to reset the match after the first character, for example:

    ^.\K.*$
    

    If you can't use \K, you should be able to use a negative look-ahead to ignore the first character of the string:

    (?!^.).*$
    

    (?!something) is a negative look-ahead which ensures that whatever follows that matches what's in the parentheses is NOT included in the match. ^. is the character immediately following the start of the string.