Search code examples
regexnotepad++

Replace first regex character using Notepad++


I want to replace first regex character in notepad++

Ex:

*abc|123
 bcd|345
*efg|4567

Result should be

abc|123
bcd|345
efg|4567

I tried

Find: ^.?(.*)
Replace: \1

But its deleting the first character of every line.Please let me know if there any other way.

Thanks in advance


Solution

  • To remove all non-word/non-linebreak at the start of the line use

    ^[^\w\n\r](.*)
    

    and replace with \1 or $1.

    Details

    • ^ - start of a line
    • [^\w\n\r] - any non-word char except an LF and CR symbols (most often used line break chars)
    • (.*) - Group 1: any 0+ chars up to the end of the line (greedy match)
    • \1 or $1 - a replacement backreference to the Group 1 contents.

    enter image description here