0

This regex pattern works everywhere except in Apex. Can anyone help me with this

Http httpProtocol = new Http();
HttpRequest request = new HttpRequest();
String endpoint = 'https://developer.salesforce.com/docs/get_document_content/object_reference/sforce_api_objects_profileskillshare.htm/en-us/244.0';
request.setEndPoint(endpoint);
request.setMethod('GET');
HttpResponse response = httpProtocol.send(request);
String jsonString = response.getBody();
Map<String, Object> m = (Map<String, Object>)JSON.deserializeUntyped(jsonString);
Pattern tag_pattern = Pattern.compile('(?m)(?=<samp class=\"codeph nolang\">)(.*?)(?=<\\/samp>)');
system.debug(tag_pattern.pattern());
String s = String.valueOf(m.get('content'))
    .replaceAll('\\n','')
    .replaceAll('<(hr|br)\\s?>','<$1/>')
    .replaceAll('<!-- -->','');
Matcher patternMatcher = tag_pattern.matcher(s);
system.debug(patternMatcher.group(1));

I am trying to get Salesforce Apex Standard supported calls https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/sforce_api_objects_account.htm They are contained in tag called
<samp class="codeph nolang">{text}</samp>

1 Answer 1

0

This works

Http httpProtocol = new Http();
HttpRequest request = new HttpRequest();
String endpoint = 'https://developer.salesforce.com/docs/get_document_content/object_reference/sforce_api_objects_profileskillshare.htm/en-us/244.0';
request.setEndPoint(endpoint);
request.setMethod('GET');
HttpResponse response = httpProtocol.send(request);
String jsonString = response.getBody();
Map<String, Object> m = (Map<String, Object>)JSON.deserializeUntyped(jsonString);
Pattern tag_pattern = Pattern.compile('(?m)(?=<samp class="codeph nolang">)(.*?)(?=</samp>)');
system.debug(tag_pattern.pattern());
String s = String.valueOf(m.get('content'))
    .replaceAll('\\n','')
    .replaceAll('<(hr|br)\\s?>','<$1/>')
    .replaceAll('<!-- -->','');
Matcher patternMatcher = tag_pattern.matcher(s);
while(patternMatcher.find()) {
    system.debug(patternMatcher.group(1));
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .