Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialManish Giri
16,266 PointsIs there a way to avoid escaping backslashes in Java Regex?
Throughout the video, the examples using regex required escaping the \
to be interpreted as a regex, like - skills.split("\\W+");
.
This can get very tedious if you have a lot of characters using the \
, like \d
, \w
, \W
. Is there a way to write Regex without having to escape the backslash? Like the way in JavaScript you can write regex anywhere in your code inside / /
, without having to escape anything.
Example - /\d{3}\s*\w{4}/g.match(str)
2 Answers
Livia Galeazzi
Java Web Development Techdegree Graduate 21,083 PointsWell, yes, it's tedious. But no, there isn't a way to write regex without escaping backslash characters. You don't usually use regex as much with java as you do with javascript, though.