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

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

String folder = path.getParent();

String filename = path.getName();