function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Regex escape

Hey guys,
I'm trying to implement a regex, and I can't figure out what the hell I'm doing wrong and what to escape... I keep getting 'invalid characters sequence' in whatever I try.

Here is the regex: ^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?

It will return me groups of the url parsed. I'm supposed to do something like the following:
Pattern myPattern = Pattern.Compile('^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?');
matcher myMatcher = myPattern.matcher(pUrl);

for(integer i = 0; i < myMatcher.groupCount();i++){

I've tried backslash escaping the backslashes, double escaping, using Pattern.Quote(), murdering coworkers.... Nothing works.

It would be awesome if someone built a javascript tool that properly escaped the chracters just for picky ol' salesforce.
I shoudl mention the regex is from the Uniform Resource Identifier specification:
*clears throat*