A regular expression (abbreviated regex or regexp) is a sequence of characters that forms a search pattern, mainly for use in pattern matching with strings, or string matching, i.e. "find and replace"-like operations.

learn more… | top users | synonyms (1)

7
votes
1answer
514 views

How to replace 'MyFirstName' by 'My First Name'

Is there any easy way, by using regex and replaceAll method, to tranform MyFirstName by My First Name. I know I could loop through each character but I was wondering if it was possible to do that in ...
1
vote
0answers
17 views

Parsing “RE” and “FWD” in email subject lines

I'd like a sanity check on a regex modification I made. The below code parses out leading "Re:" and "Fwd": in an email subject line and captures the remainder of the subject line. It works, but ...
2
votes
3answers
54 views

How to find all numbers in a string using Regex

I am trying to extract all numbers from a string but I got the below code to work although it stops after the first match for 123. String str = '123-456/7890'; Pattern p = Pattern.compile('(\\d+)'); ...
1
vote
1answer
27 views

Regex to validate a generic CSV

I have two questions in order to make a custom csv importer in VF/Apex. I saw many samples out there but I'm not able to find validations samples. 1) I would like to know if is any regex to validate ...
2
votes
1answer
25 views

Complete Regex Reference For Salesforce Formulas?

Is there a complete Regex Reference somewhere for using REGEX() in formulas? I have searched and found nothing useful. The problem I am having is below. I want to know if any of the characters ...
0
votes
2answers
132 views

Regex Validation rule for telephone number

I want to create a validation rule on Phone field(Custom) where system will be allowed to use + or 00 and then 7 to 26 digits(Numeric). Also in between if I enter any space or dash that should not be ...
1
vote
1answer
32 views

Strange behaviour of Regex to allow only alphabets in the name field

I have a validatio rule on contact which gives error when the name field contains non-alphabetic character. Formual for the Vaildation rule is as follows : OR( REGEX( FirstName , "[a-zA-Z]+"), ...
3
votes
4answers
1k views

Best REGEX for first/last name validation?

Looking to stop people putting initials in the First / Last name fields, plus any special characters that you would not associate with a name. I've got something, although it is coming unstuck on ...
2
votes
2answers
179 views

Finding substring with regex for contents of <tr> tags

I am using regex patterns to search this string: ...
1
vote
2answers
198 views

Check if string contains specific characters- Validation Rule

I have a field text that cannot contain either l m or p whether it is upper or lower case. How can I accomplish this in a validation rule? Please give examples. Perhaps a regular expression example ...
0
votes
1answer
75 views

REGEX for stripping http://, https:// and www from website

For a custom field "Domain," I want to strip extraneous elements like those in the subject line, which often end up in the field through web-to-lead. Can anyone suggest a REGEX formula for stripping ...
0
votes
0answers
253 views

Creating REGEX for replacing all special characters except those between quotes

I need to build a regula expression to replace all the special characters in the string with space except those between quotes.I tried [^\w\'] but it replaces special characters ...
0
votes
1answer
115 views

Replacing multiple consecutive spaces with Pipe character

I need to replace multiple consecutive spaces with pipe character ,I tried various regular expression but i couldn't get the output .Can anyone give me solution for this
0
votes
2answers
377 views

Extracting special character in salesforce Apex

I Have a string like "Hello-how@are you!" I want to get which special characters the string contains I searched for an hour i able to get the thing like replacing the special characters But i need ...
2
votes
1answer
95 views

Matcher not finding text within <> (e.g., HTML tag)

Does anyone know why the Matcher in Salesforce does not find text contained within <> (the "less than" and "greater than" signs)? The sample code below, adapted from "Using Patterns and ...
3
votes
1answer
154 views

SFDC regular expression to catch the word with repeated characters

I am going to use the regular expression to catch the word with repeated characters (letter, digit, or underscore). I found pretty interesting results during my testing. If I am using apex code, ...
4
votes
2answers
721 views

How do you check email format in Apex?

If I have a form for candidates to apply for certain jobs online, when a candidate enters his email and submits the form, I want my controller to validate the email format that was entered. Can ...
0
votes
1answer
218 views

I need a regex to find line breaks in a text area field in salesforce

I have a field of type 'Text area' With a paragraph of sentences with line breaks.it looks like this : "test regex for Text area with line breaks" The regex i used is : ...
4
votes
3answers
102 views

Regular Expression and Matcher issues

Does anyone know why this will not find the match. I'm running this code public string cleanEmail(String body){ String result; String RegExp = ...
2
votes
1answer
82 views

matcher.groupCount() always returns 1

I try to extract all mergefields out of an email template, but my matcher just finds the first one. groupCount is always 1. Im new to salesforce. Please help. pattern mrgflds = pattern.compile ...
3
votes
1answer
166 views

Regex a datetime from JSON and convert to miliseconds

I've JSON like this: "to" : "2013-11-28T20:58:00.000+0000", Which I want to make into: "to" : "/Date(1296547200000)/", The furthest I got with regex is replaceAll('(?m)(?i)"from" : "(.+?)("$)', ...
6
votes
3answers
944 views

Unable to use multiline with pattern

I'm trying to match a string with Pattern/Matcher, however it is failing because I cannot set Pattern.MULTILINE like the Java documentation uses. String testString = 'Line 1: Does not match\nCustomer ...
-2
votes
1answer
1k views

Pulling picklist options from a multi-value field

I am currently pulling select options for a multi-value picklist from a query which gathers field values from all of the child records from a certain __r relationship of an account. I would like to ...
4
votes
2answers
762 views

“REGEX too Complicated” error

Is "REGEX too Complicated" error while attempting to upload a CSV via Apex into SFDC an undocumented limit? What should be the optimal data volume for a CSV upload via Apex? I was trying with 10,000 ...
2
votes
1answer
394 views

Formatting phones to E.164

I'm trying to validate a phone number in the E.164 format using a RegEx, but it doesn't seem to be working. Here's the RegEx: java Pattern e164p = Pattern.compile('\+?\d{10,14}'); Error message: ...
4
votes
1answer
1k views

Get the content between the nearest Square Brackets in a string

In the following string, ['*.*string1*.*'],['*.*String2*.*'],['*.*String3*.*'],['*.*String4*.*],['*.*String5*.*] how can get the content including the brackets which are in String 4 using Regex ...
7
votes
1answer
471 views

“Maximum stack depth reached: 3” when doing String.replaceAll()

I am getting a strange "Maximum stack depth reached: 3" when doing a String.replaceAll() with bigger Regex on a quite big string (40 lines of text). I am trying to remove any comments and literal ...
6
votes
2answers
286 views

Regexp to extract parts of ApexClass.Body

I want to calculate some metrics on Apex classes. So I need to somewhat "parse" them with the means that exist in Apex e.g. regexp patterns, groups and regions. I want to match class declarations ...
6
votes
2answers
320 views

Find out if a given string is Salesforce Id in Java

Is there a way(regex or something) to find out if a given string is a Salesforce Id or not? I'm looking for some helper class in Java.
1
vote
1answer
551 views

Using RegEx Pattern Match to create DateTime fields in trigger

How do I write code with the correct syntax to run a pattern grouping match within a string, then replace the pattern groups found in the result so that they follow a desired pattern? I've never done ...
2
votes
4answers
342 views

RegExp to extract namespace prefix from SObject name

I want to get a potentially empty namespace prefix from arbitrary sobject names by using Regexp. All following cases should be covered: 1. StandardObject 2. CustomObject__c 3. ...
9
votes
2answers
2k views

How do I do a case-insensitive replace all for a string?

I've got a project where I'd like to replicate some of the internal merge field functionality so users can build a link and it'd be really helpful if I could do a case-insensitive string replaceAll. ...
0
votes
1answer
228 views

Regex NullObject in Trigger if run from Dataloader else works fine

Fellow developers, I have a call to an email validation function in my before insert in my trigger, which basically puts the email blank if its not valid (according to the regex) public static ...
3
votes
2answers
335 views

Regex replacement efficiency

In a recent question (Remove whitespaces in a string) my solution included using a simple regex replacement (\\s+) to match all instances of double spaces (or more) and reduce them to a single space. ...
1
vote
1answer
677 views

How to validate UTF-8 in regex

I have basic validation rules setup for name fields: NOT(REGEX(FirstName, "^[A-Za-z\\. '-]+$")) The goal is to only allow letters, periods, spaces, hyphens and apostrophes in the name field. The ...
4
votes
2answers
4k views

How do I use regular expressions in Apex to extract data from a string?

Assuming an input string is a well formed duration in the form "1hr 30m", how can I get the 1 and 30 out and into their own variables?