Podcast #128: We chat with Kent C Dodds about why he loves React and discuss what life was like in the dark days before Git. Listen now.

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
0
votes
0answers
16 views

Regular Expression chapter extracting [on hold]

input 1.1 My cow always gives milk 1.2 My cow always gives milk My 1.3 cow always gives milk 1.4 output: 1.1 My cow always gives milk 1.2 My cow always gives milk My 1.3 cow always gives I need ...
2
votes
0answers
22 views

Pattern is not working in class but working in anonymous block

I am trying to extract a string from an XML using the Regex. I am able to extract the desired result when I run below code in anonymous code from the developer console. String textString = '<?xml ...
1
vote
1answer
47 views

Using replace() to remove a value from an array in LWC with a RegExp

I just want to remove a value from an Array in LWC using the method replace with RegExp. @track myList = ['a', 'b', 'c']; @track removeValue = 'b'; if (this.myList.includes(this.removeValue)) { ...
0
votes
1answer
28 views

Javascript Controller capitalize and remove accents [on hold]

I use in a javascript controller the function for every variable string str that i have in a custom lightning component str.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toUpperCase().trim() in ...
0
votes
1answer
28 views

Format Phone Number in Auto launch Flow

I need the flow to load a Phone number record into a custom setting without any dashes or parentheses. Ex. (440)-111-2222 into 4401112222. I am trying to use Regex to do this and not having any luck. ...
0
votes
2answers
27 views

Regular Expressions - Regex for specific characters!

Which is the Regex for these symbols? -, –, %, /, ., "", «», '', ', <, >, &, :, (, ), !, ^, * Ι need to Replace them all with Space.
0
votes
0answers
11 views

REGEX in Process Builder Not Working as Expected

Background I've set up a process (in Process Builder) to update the MobilePhone field on the Contact object to this format: +614xxxxxxxx when it is entered in this format: 04xxxxxxxx. It has been ...
0
votes
2answers
39 views

REGEX Validation rule for multiple lines of dates

I'm trying to find a regex pattern for a validation rule on an opportunity that will allow dd/mm/yyyy one or more lines in a long text field named Dates_offered__c. For example, I want to allow: dd/...
2
votes
1answer
80 views

Handling multiple regex matches in Ampscript

Given this string: SET @text = "<a href=""https://salesforce.stackexchange.com""target=""_blank"">Salesforce</a> <a href=""https://stackoverflow.com"" target=""_blank"">Everything ...
0
votes
1answer
57 views

SQL exclusion regexp

I have a data extension with a level field based on the subscription level of customers. The fieldcontains 4 options, beginner, intermediate, expert and when they choose nothing it is unspecified(...
0
votes
1answer
26 views

Validation Rule for Phone with Extension

I'm trying to write a validation rule for phone numbers with extensions. I want to be sure there are exactly 10 integers to the left of the letter "x". It needs to ignore special characters and only ...
2
votes
1answer
42 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
25 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
49 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
82 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
60 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
16 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
23 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-...
2
votes
1answer
65 views

Pattern.matches - searching an entire string vs a substring

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
42 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
50 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
341 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
60 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
301 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
233 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
39 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
65 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
69 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
92 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
241 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
69 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
24 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
28 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
304 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
50 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
76 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
141 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
670 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
45 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
32 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
246 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
94 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
2k 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
34 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
102 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
840 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
62 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
304 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 && ...