Thank you for filling out a Git bug report! Please answer the following questions to help us understand your issue. What did you do before the bug happened? (Steps to reproduce your issue) mkdir test cd test git init cat >a.txt <<EOF NRZ /NZRQ/NBRQ/ NRZ(C) /NZRCQ/ NRZ(M) /NZRMQ/ EOF git add a.txt git commit -m 1 cat >a.txt <<EOF NRZ /NZRMQ/NZRCQ/NZRQ/NBRQ/ EOF git diff --word-diff-regex=. What did you expect to happen? (Expected behavior) diff --git a/a.txt b/a.txt index 278ea76..7e6f42f 100644 --- a/a.txt +++ b/a.txt @@ -1,3 +1 @@ NRZ /NZR{+M+}Q/N[-BRQ/-]{+ZRCQ/NZRQ/NBRQ/+} [-NRZ(C) /NZRCQ/-] [-NRZ(M) /NZRMQ/-] or anything whose hunk has three lines What happened instead? (Actual behavior) diff --git a/a.txt b/a.txt index 278ea76..7e6f42f 100644 --- a/a.txt +++ b/a.txt @@ -1,3 +1 @@ NRZ /NZR{+M+}Q/N[-BRQ/-] [-NRZ(C) /N-]ZRCQ/N[-R-]Z[-(M) -]{+RQ+}/N[-Z-]{+B+}R[-M-]Q/ What's different between what you expected and what actually happened? some newlines are ignored and the length of the hunk is wrong; git says "@@ -1,3 +1 @@" but the hunk has only 2 lines Anything else you want to add: this may be clearer with --word-diff=porcelain because it doesn't emit enough number of "~"s ``` $ git diff --word-diff-regex=. --word-diff=porcelain diff --git a/a.txt b/a.txt index 278ea76..7e6f42f 100644 --- a/a.txt +++ b/a.txt @@ -1,3 +1 @@ NRZ /NZR +M Q/N -BRQ/ ~ -NRZ(C) /N ZRCQ/N -R Z -(M) +RQ /N -Z +B R -M Q/ ~ ``` this should emit 3 tildes Please review the rest of the bug report below. You can delete any lines you don't wish to share. [System Info] git version: git version 2.46.0 cpu: x86_64 no commit associated with this build sizeof-long: 8 sizeof-size_t: 8 shell-path: /bin/sh libcurl: 7.68.0 zlib: 1.2.11 uname: Linux 5.15.153.1-microsoft-standard-WSL2 #1 SMP Fri Mar 29 23:14:13 UTC 2024 x86_64 compiler info: gnuc: 9.4 libc info: glibc: 2.31 $SHELL (typically, interactive shell): /bin/bash [Enabled Hooks]