# Regex \\w and \\\\w is not working

**URL:** <https://discourse.processing.org/t/regex-w-and-w-is-not-working/1478>\
**Category:** Coding Questions\
**Created:** [July 3, 2018, 9:11pm UTC](https://discourse.processing.org/t/regex-w-and-w-is-not-working/1478 "2018-07-03T21:11:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tomte55](https://avatars.discourse-cdn.com/v4/letter/t/ac8455/32.png) [@tomte55](https://discourse.processing.org/u/tomte55)\
**Post date:** [July 3, 2018, 9:11pm UTC](https://discourse.processing.org/t/regex-w-and-w-is-not-working/1478/1 "2018-07-03T21:11:21Z")

</div>

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:

```auto
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

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [July 3, 2018, 11:36pm UTC](https://discourse.processing.org/t/regex-w-and-w-is-not-working/1478/2 "2018-07-03T23:36:40Z")

</div>

[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#getParent())  
[https://Docs.Oracle.com/javase/10/docs/api/java/io/File.html#getName()](https://Docs.Oracle.com/javase/10/docs/api/java/io/File.html#getName())

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

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

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

exit();

```
