Regex \w and \\w is not working

I’m making a rename function where you input a filepath then a name.
Then the function is going to find the last entry in the filepath and replace it with the inputted name,

And the filepath input is something like this: C:\Users\user\test

With this filepath what i expect it to find is “test”.

And this is inside the function:

void rename_file (String path1, String path2) {
  path1.replaceFirst("(?!\\)\\w+$", path2)
}

When i run this function it throws this error: Not expecting symbol ‘w’, which is LATIN SMALL LETTER W.

And if i use \w it throws this error: PatternSyntaxException

I have tried this regex in atom and there it works with just \w

https://Docs.Oracle.com/javase/10/docs/api/java/io/File.html#getParent()
https://Docs.Oracle.com/javase/10/docs/api/java/io/File.html#getName()

File path = dataFile("test.txt");
println(path);

String folder = path.getParent();
println(folder);

String filename = path.getName();
println(filename);

exit();