Questions tagged [regular-expressions]

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.

Filter by
Sorted by
Tagged with
2
votes
1answer
23 views

Only the first IF condition works, and the rest doesn't when nested in Process Builder formula

GOAL: I'm trying to create this criteria in Process Builder where I can detect phone number like (000) 000-0000, 000-000-0000 and 000.000.0000 and turn them into +1 0000000000 format. I tried to ...
0
votes
0answers
24 views

Trying to get a regular expression to work in the process builder in Salesforce

AND( ISCHANGED([Contact].Years_Donated__c ), NOT(ISBLANK([Contact].Years_Donated__c )), NOT(REGEX([Contact].Years_Donated__c , "/(^|(.)(?!\2))(\d)\3{3}(?!\3)/" ) I am trying to ...
1
vote
2answers
41 views

Split string in equal length to avoid 'regex too complicated exception'

Here I have to replace 6 keywords from the response. I have created a metadata with word and replaced word. public static String replaceJSONKeywordsModified(String strJsonResponse) { String ...
-3
votes
1answer
41 views

Regular Expression to get Street Name and Number Separately

I am using the compile method for the pattern class in order to separate digits (street house number) from a string into a number field, and the non-digits (street) into a string field. \d* gives me ...
-1
votes
1answer
58 views

Regex in Pattern.compile to split BillingStreet into custom street and house number field

I want to split BillingStreet into a custom Street__c and HouseNumber__c. According to what I have read so far online, I need to: Instantiate a new Pattern object //Pattern 'Test Street 123' OR '123 ...
0
votes
1answer
11 views

Regex for Text Field in Flow screen input validation gives error

REGEX( {!Phone} , "((^[?+\+\s]|^[\d]?)([\s\-\.]?)([\d]{1,3})([\s\-\.\(]*)([\d]{3})([\s\-\.\)]*)([\d]{3})([\s\-\.]*)([\d]{4})$)" ) Phone (Screen Component) - The formula expression is invalid: ...
0
votes
0answers
17 views

Phone (Screen Component) - The formula expression is invalid: Syntax error

I have Text field on Flow Screen component that I use for Phone number. In validate input section i have wrote REGEX({!Phone} , "^(\+(([0-9]){1,2})[-.])?((((([0-9]){2,3})[-.]){1,2}([0-9]{4,10}))|([0-...
1
vote
1answer
48 views

Struggling with Pattern.matches

My regular expression is working properly here: https://regexr.com/4j143 However, when I try to use it in Apex it is not working: String regExp = '/\\s{1,}(ORDER BY)\\s{1,}(ID)(\\s{1,}(ASC)){0,1}(\\...
0
votes
1answer
34 views

REGEX in Validation Rule

I have a custom field on an object which should allow values based on the following JavaScript REGEX. /[^\sa-zA-Z0-9.,:?;%/()'!""-]/g Can anyone help me how to use this REGEX in validation rule ?
0
votes
1answer
28 views

Validation rule that allow only number along with a specific string

I want a validation rule that should allow only number (0-9) and a specific string ('N/A') which contains a special character also. NOT(REGEX(Code__c, "[0-9,;N/A]*")) The above validation rule is ...
0
votes
2answers
27 views

Regex for 13 digit number, last four digit should only be 0 to 3

I have added regex ([0-9])\13 ^0-4, total 13 digit number will allow and last four digit should be between 0 to 3 but this is not working. ([0-9])\13 ^0-4) for ex: 1234567890123 or 7891534572103 ...
2
votes
3answers
81 views

Validation rule to allow number, decimal and percentage

I am trying to write a validation rule which will allow only numbers, decimal and % symbol. Below are the samples i am trying but it is not working. If I put 17.5% it is not working Any number upto ...
0
votes
1answer
41 views

Best way to spot non-GSM characters in a string?

There are other posts here re: Apex matcher functions and replacing characters in a string. I simply need to know if a given string contains any non-gsm chars. GSM refers to a standardized set of ...
0
votes
1answer
35 views

How do I replace all non-digit characters in a regex except for the period?

In my VF page I have some Javascript to format passed variables. I have a string eg "Cost is $100.00" from which I need to remove all non-digit characters, EXCEPT the digital period. I want the result ...
0
votes
2answers
71 views

apex regex validation. for version number string

I am trying to validate a version number string. something like #.#.#.# can you please tell me if the below is correct ^[0-9]{1,2}(.[0-9]{1,2})? how do i restrict this to just 4 decimals?
-2
votes
1answer
34 views

Is it possible to do a “reverse regex” pattern match?

I have the following code: if(PATTERN_A.matcher(someValue).matches()){ model = MODEL_A; } else if(PATTERN_B.matcher(someValue).matches()){ model = MODEL_B; } else if(PATTERN_C.matcher(...
2
votes
1answer
50 views

Regex - Syntax error

This is my regex (for international phone number), i have the message "Syntax Error" with this part of regex highlighted : s*[)]?[-\s.]?[(]?[0-9]{1,3}[)]?([-\s.]?[0-9]{3})([-\s.]?[0-9]{3,4})') ...
4
votes
1answer
54 views

REGEX Validation Rule for Phone Number [closed]

I am trying to create a validation rule for phone number and using the following regex Validation : NOT(REGEX( Phone, "^(?=.*?[1-9])[0-9()/\\-\\+\\s\\.\\ ]+$")) The above regex is working fine if ...
-2
votes
1answer
49 views

Regex validation for us phone

when I am using lighting input and using pattern its works <aura:application extends="force:slds" > <aura:attribute type="string" name="phone" /> <lightning:input type="phone" ...
0
votes
1answer
131 views

Apex Email Validation [duplicate]

String email ='shilpa..test@gmail.com' Boolean isValid = Pattern.matches('([a-zA-Z0-9_\-\.]+)@((\[a-z]{1,3}\.[a-z]{1,3}\.[a-z]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{1,}|[0-9]{1,3})',email); ...
3
votes
1answer
50 views

Pattern Matcher finds match but cannot get text due to \r - works fine in regex testers

For the given text obtained from a text area field: Apex script unhandled exception by user/organization: xxx/xxx Visualforce Page: /apex/pagename caused by: System.NullPointerException:...
1
vote
1answer
21 views

Regex Replace All causes misses

I'm working on regex in order to replace some strings public static String removeValuesByRegex(String input, Pattern pattern, String replaceWith){ String result; Matcher matcher = pattern.matcher(...
0
votes
0answers
26 views

Need a small regex help

Needed some help while constructing the below pattern for salesforce contact Phone Field Condition1: must start with ‘0’ Condition2: can only be followed by digits and spaces. Condition3: minimum ...
2
votes
1answer
199 views

Regex for certain words causes Spaces

For instance i'm trying to search this string "this is a search LLC which can end up having spaces" using the below regex, it's working fine but when I match and then remove it's causes a bunch of ...
0
votes
2answers
41 views

Replace + Sign by Underscore

Trying to replace a character '+' with underscore. Tried: String s = 'Happy+Me'; System.debug(s.replaceAll('\\+', '_'); System.debug(s.replaceAll('/\[+]', '_'); Still gives me 'Happy+Me' result. ...
-3
votes
1answer
61 views

How to write a method to remove non alphanumerics in a string and display it in a list [duplicate]

method to remove non alphanumerics in a string and display it in a list. public static list<string> s(){ String stg = 'ABC,DEF,GHI,JKL'; List<String> lst = stg.split(','); ...
3
votes
1answer
137 views

Regex implementation in Salesforce: getting from known string to end of the line

I have an email service that parses an email and inserts or updates a set of fields. I have trawled through previous questions and can see that many regex posts are voted down for being not '...
1
vote
1answer
528 views

Check if string contains a number or a special character

Regex newbie here, I'm trying to create a validation rule which will restrict users from entering a number or a special characters to a certain field. This is what I have so far: !IsNew() && ...
1
vote
1answer
41 views

Regex on timestamp expression

I am trying to check if a string matches the whole expression using the following code: String expression = '^(19|2[0-9])[0-9]{2}-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])T(0[0-9]|1[0-9]|2[0-3]):([0-5]...
0
votes
2answers
31 views

Regex finding 22 numbers in a string

So I have a database string which is <@$244230034359844866> <@$244230033359844566>. How would I make it so that when I do console.log it only shows up with 244230034359844866, ...
2
votes
1answer
213 views

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: ...
1
vote
2answers
85 views

Problem with Regex/Pattern/Matcher

I'm trying to implement the ideas in this post in my org. However, the provided regex seems to never match anything in any email I throw at it. The simplest possible test case I can muster is: ...
2
votes
2answers
1k views

Regular Expression matches returns false

I am using this regular expression: String regex = '(\\d{11}|\\d{5} \\d{6}|\\+\\d{12})'; Pattern compiledPattern = Pattern.compile(regex); Matcher match = compiledPattern.matcher('Inbound Call at 5:...
0
votes
1answer
1k views

Invalid string literal '^.*\s(\d+)\s.*$'. Illegal character sequence \s' in string literal [duplicate]

I want to use the below regex string: private final String regex = '^.*\s(\d+)\s.*$'; In a Pattern: private Pattern pattern = Pattern.compile(regex); But I am getting this error: Illegal string ...
0
votes
1answer
31 views

Regex expression in Validation Rule

I have the following validation rule with regex expression. I have tested the expression working to my need but can't able save this coming up with syntax error could someone help me to get this ...
2
votes
1answer
91 views

How to process image URLs in Email Services?

I have written an inbound email service to created records based on custom object. This email service processes replies to the outbound email sent from Salesforce. The outbound email's template and ...
0
votes
1answer
650 views

Regex validation for Phone Number

I am trying to create a validation rule for US format number and using the following regex Validation NOT(REGEX(Phone, "\\D*?(\\d\\D*?){10}")) The above seems like a standard regex which will only ...
0
votes
1answer
42 views

Regular expression : I need to retrieve a part of a string into a string

I have a string that could be of this kind, for example : String text = 'test AZ123AZ testtesttest'; I need to retrive this part of the string : AZ123AZ So for now I have something like this ...
1
vote
1answer
144 views

Validation Rule for Number only in Salesforce is throwing an error for (XXX) XXX-XXXX format

I have 3 phone fields in Salesforce Contact. I am supposed to prevent users from entering characters in the phone field. I have used the below validation rule ( Phone != null && ...
-1
votes
1answer
417 views

Regex for email validation [closed]

I have created a regex for email validation which will check the email is in proper format or not. Regular expression for the email is [a-zA-Z0-9._-]+@[a-zA-Z]+.[a-zA-Z]{2,4}[.]{0,1}[a-zA-Z]{0,2} ...
0
votes
2answers
248 views

Regex is not working - For getting method body from a class body in string format

I am not able to find regular expression for getting only the methods from a class body which is in String format. Apexclass sampleApexClass = [SELECT body from ApexClass Where name = <SomeClass&...
4
votes
1answer
222 views

Issues with Regex matcher on APEX

I'm looking to create a regex that will grab all of the lines of text which comply with the following structure: Group1: 2-3 chars of upper case letters Group2: A datetime of day month and year with ...
1
vote
1answer
53 views

Regex puzzle, limit optional first character to one of two values

I am working up a regex that will match if the first character is 'S', 'U', or absent. I've gotten it to match the two characters just fine, but I can't figure out how to match the absent character. ...
0
votes
2answers
862 views

Validation rule to allow 15 digits only

Please advise a validation rule to allow me to enter 15 digits only. If the number of entered digits is higher or less than 15 the validation rule should display an error message. If there are ...
0
votes
0answers
37 views

Need help parsing email body

I have an email service where clients can send me yes/no answers to questions I ask yet a lot of responses include narratives such as, "No, I do not like green eggs and ham," (and others). Rather ...
1
vote
1answer
259 views

Check if email to/from string contains external domains using regex

I have a string in Salesforce that contains the to and from addresses of an email, e.g.: From: sender@gmail.com to: (recip1@yahoo.com, recip2@icloud.com) A process should set a picklist to internal ...
0
votes
1answer
84 views

REGEX for 4 decimal places [closed]

I want REGEX to allow only 4 decimal places no more and no digits. Requirement is at least 1 decimal and up to 4. This is what i have: REGEX(TEXT(Won_Lost_By_How_Much__c),"\\.[0-9][0-9]?[0-9]?[0-9]?"...
3
votes
1answer
3k views

lightning:input (text) - is it possible to have multiple patterns

I have a field that checks for 2 patterns. What I currently have is, in the text field's onchange handler, i check if the inputted string matches a certain pattern. However, I want to use lightning's ...
0
votes
1answer
1k views

String Contains only alphabetical REGEX

My below code doesn't return true in result: String NameRegex = '/^[A-z]+$/'; Pattern MyPattern = Pattern.compile(NameRegex); Matcher MyMatcher = MyPattern.matcher('TEST'); Boolean result = MyMatcher....
0
votes
1answer
331 views

patern and matcher not working

I am using regex to find line which starts with 'aaaa' pattern myPattern = pattern.compile('^(aaaa)\b.*'); String a = 'aaaa,777,ttttt,rrrrrr'; a += '\n' + 'tttttt,ttttt,0000'; matcher myMatcher = ...