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
mlundwallmlundwall 

substring regexp in select query

Hi,

 

Is there any way touse substring and/or regular expressions in SOQL Select statements? The query I would like to do is something like:

new List<Account>([SELECT Id, Store_ID__c FROM Account WHERE Website = :domain_query])

Where domain_query is a stripped version of the domain. ie: google.com would be google

The Website field should therefor be stripped from http://, the country suffix and possibly www if it is there. http://www.google.com -> google

 

I could use a LIKE comparison and then use a loop to check for equality but that isn't a nice solution...

 

Any ideas?

Best Answer chosen by Admin (Salesforce Developers) 
SteveBowerSteveBower

Well, you can't do it directly in the SOQL, however Apex String objects have a replaceAll() and replaceFirst() method which support regular expressions.  

 

Or, you could use split on a Period.

 

List<String> tmp = domain_query.split('\.');

 

domain_query = tmp[tmp.size()-1];     // take the argument before ".com"    

 

Best, Steve.

 

 

All Answers

SteveBowerSteveBower

Well, you can't do it directly in the SOQL, however Apex String objects have a replaceAll() and replaceFirst() method which support regular expressions.  

 

Or, you could use split on a Period.

 

List<String> tmp = domain_query.split('\.');

 

domain_query = tmp[tmp.size()-1];     // take the argument before ".com"    

 

Best, Steve.

 

 

This was selected as the best answer
mlundwallmlundwall

Ok, thanks