+ Start a Discussion
JayNicJayNic 

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);
myMatcher.matches();

for(integer i = 0; i < myMatcher.groupCount();i++){
    system.debug(
	    myMatcher.group(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.
JayNicJayNic
I shoudl mention the regex is from the Uniform Resource Identifier specification: https://tools.ietf.org/html/rfc3986#appendix-B
JayNicJayNic
*clears throat*