diff --git a/syntax/just.vim b/syntax/just.vim
index f8c4c16..d05ec82 100644
--- a/syntax/just.vim
+++ b/syntax/just.vim
@@ -37,8 +37,13 @@ syn region justString start=/"""/ skip=/\\\\\|\\"/ end=/"""/ contains=justLineCo
syn cluster justStringLiterals contains=justRawString,justString
syn cluster justAllStrings contains=justBacktick,justRawString,justString
-syn match justRegexReplacement /\v,%(\_s|\\\n)*%('\_[^']*'|'''%(\_.%(''')@!)*\_.?''')%(\_s|\\\n)*\)/me=e-1 transparent contained contains=@justExpr,@justStringsWithRegexCapture
-syn match justRegexReplacement /\v,%(\_s|\\\n)*%("%(\_[^"]|\\")*"|"""%(\_.%(""")@!)*\_.?""")%(\_s|\\\n)*\)/me=e-1 transparent contained contains=@justExpr,@justStringsWithRegexCapture
+syn match justRegexReplacement
+ \ /\v,%(\_s|\\\n)*%('\_[^']*'|'''%(\_.%(''')@!)*\_.?''')%(\_s|\\\n)*%(,%(\_s|\\\n)*)?\)/me=e-1
+ \ transparent contained contains=@justExpr,@justStringsWithRegexCapture
+syn match justRegexReplacement
+ \ /\v,%(\_s|\\\n)*%("%(\_[^"]|\\")*"|"""%(\_.%(""")@!)*\_.?""")%(\_s|\\\n)*%(,%(\_s|\\\n)*)?\)/me=e-1
+ \ transparent contained contains=@justExpr,@justStringsWithRegexCapture
+
syn region justRawStrRegexRepl start=/\v'/ end=/'/ contained contains=justRegexCapture
syn region justRawStrRegexRepl start=/\v'''/ end=/'''/ contained contains=justRegexCapture
syn region justStringRegexRepl start=/\v"/ skip=/\\\\\|\\"/ end=/"/ contained contains=justLineContinuation,justStringEscapeSequence,justRegexCapture
diff --git a/tests/cases/replace_regex-captures.html b/tests/cases/replace_regex-captures.html
index d151a8d..4115c0c 100644
--- a/tests/cases/replace_regex-captures.html
+++ b/tests/cases/replace_regex-captures.html
@@ -32,6 +32,18 @@
foo8 := replace_regex("test123", '\w(\d+)', '''
\t'$1''')
+foo9 := replace_regex("trailing comma is accepted after the final argument,",
+ "(\\W+)", \
+ "${1}_$1",
+)
+
+foo10 := replace_regex("_abcdef",
+ '(\w)[a-z]+', \
+
+ '${1}'
+ , \
+)
+
not_a_replacement := 'test $1 test '
not_a_replacement_2 := "test $Abc_ test"
diff --git a/tests/cases/replace_regex-captures.just b/tests/cases/replace_regex-captures.just
index feeba46..8cf9885 100644
--- a/tests/cases/replace_regex-captures.just
+++ b/tests/cases/replace_regex-captures.just
@@ -32,6 +32,18 @@ foo7 := replace_regex("Some text.", '([^a-z])', '$$1')
foo8 := replace_regex("test123", '\w(\d+)', '''
\t'$1''')
+foo9 := replace_regex("trailing comma is accepted after the final argument,",
+ "(\\W+)", \
+ "${1}_$1",
+)
+
+foo10 := replace_regex("_abcdef",
+ '(\w)[a-z]+', \
+
+ '${1}'
+ , \
+)
+
not_a_replacement := 'test $1 test '
not_a_replacement_2 := "test $Abc_ test"