Skip to main content
edited tags
Source Link

I found a Regex which retrieves the Parent domain from a URL. When I tried using the same Regex Expression in Apex using Pattern and Matcher, it's giving me an error of:

Illegal string literal: Invalid string literal '(\w+.\w+)$'. Illegal character sequence \w' in string literal.

Below is my code:

Account aa = [SELECT id, Website from Account WHERE Id = '0016F00002QeRqw'];
String d = aa.Website;
String regexx = '(\w+\.\w+)$';
Pattern mPat = Pattern.compile(regexx);
Matcher myMatch = mPat.matcher(d);
system.debug('--'+myMatch);

Link to the Regex

I am not that good in the Regex and could use some help finding the issue.

TIA.

I found a Regex which retrieves the Parent domain from a URL. When I tried using the same Regex Expression in Apex using Pattern and Matcher, it's giving me an error of:

Illegal string literal: Invalid string literal '(\w+.\w+)$'. Illegal character sequence \w' in string literal.

Below is my code:

Account aa = [SELECT id, Website from Account WHERE Id = '0016F00002QeRqw'];
String d = aa.Website;
String regexx = '(\w+\.\w+)$';
Pattern mPat = Pattern.compile(regexx);
Matcher myMatch = mPat.matcher(d);
system.debug('--'+myMatch);

Link to the Regex

I am not that good in the Regex and could use some help finding the issue.

TIA.

I found a Regex which retrieves the Parent domain from a URL. When I tried using the same Regex Expression in Apex using Pattern and Matcher, it's giving me an error of:

Illegal string literal: Invalid string literal '(\w+.\w+)$'. Illegal character sequence \w' in string literal.

Below is my code:

Account aa = [SELECT id, Website from Account WHERE Id = '0016F00002QeRqw'];
String d = aa.Website;
String regexx = '(\w+\.\w+)$';
Pattern mPat = Pattern.compile(regexx);
Matcher myMatch = mPat.matcher(d);
system.debug('--'+myMatch);

Link to the Regex

I am not that good in the Regex and could use some help finding the issue.

Source Link
Kamal Thakur
  • 426
  • 1
  • 7
  • 26

Regex having issues in Apex

I found a Regex which retrieves the Parent domain from a URL. When I tried using the same Regex Expression in Apex using Pattern and Matcher, it's giving me an error of:

Illegal string literal: Invalid string literal '(\w+.\w+)$'. Illegal character sequence \w' in string literal.

Below is my code:

Account aa = [SELECT id, Website from Account WHERE Id = '0016F00002QeRqw'];
String d = aa.Website;
String regexx = '(\w+\.\w+)$';
Pattern mPat = Pattern.compile(regexx);
Matcher myMatch = mPat.matcher(d);
system.debug('--'+myMatch);

Link to the Regex

I am not that good in the Regex and could use some help finding the issue.

TIA.