Search code examples
regexgithubgitattributes

Regex getting converted when checked-in to github


I'm having the regex in one of the file as shown below.

pattern = "^[^,&*\n\t\r]*"

But when i check-in that to github, it's getting converted to invalid characters as shown in the below image.

enter image description here

I have added the .gitattributes as shown below. Still getting this error. Any help would be appreciated.

* text=auto
*.proto text

Solution

  • I suggest using the hex notation for each of the whitespace chars:

    pattern = "^[^,&*\\x0A\\x0D\\x09]*"
    

    This way, the pattern will be passed as ^[^,&*\x0A\x0D\x09]* text and \xNN regex escapes will be parsed by the regex engine itself, not by the language engine.