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
26 views

Error escaping double quotes in large JSON string in Apex

I have large JSON response that I am trying to escape all instances of strings that are problematic for deserialization but am having some issues. Using .replaceAll works but that throws a "Regex too ...
0
votes
0answers
24 views

Regex to replace visualforce line only if not commented

I am trying to determine if the markup of a visualforce page contains a line of code and only if it is not commented out then replace it. I was hoping to do a simple string.replace with the regex ...
0
votes
1answer
25 views

Can you use Regular Expression to Conditionally display an Image Element in a Screen Flow?

I'm working on a screen flow for collecting payment information. I am currently validating card info based on the digits using REGEX, and would like to use the same formula to conditionally display a ...
0
votes
1answer
23 views

Regex validation for birthdate in the format of mm/dd

I have a custom text field with a max length of 5 characters and I'm trying to use regex to enforce a date entered in the format of mm/dd. Two digits, then a "/", followed by two digits. I was trying ...
0
votes
0answers
48 views

Regex expression for password requirements in apex

I have created a regex for a password requirements for my self registration page.This is the password requirements: Minimum eight (8) characters At least one number (0-9) Any three of the following: ...
0
votes
0answers
29 views

Regex Too Complicated when using ReplaceAll() Method in Apex…replaceAll('<!\\[CDATA\\[', '')

I am trying to use the ReplaceAll() method to replace these characters as given below in the string and add it to a htmlBody to send email to the Owners of those records in a batch class. String ...
0
votes
1answer
104 views

How to do regex for Iban internationally

I found a regex example for international iban numbers but the is returning false. What am I doing wrong. Apex public static Boolean validateIban(String iban) { Boolean res = true; ...
0
votes
0answers
25 views

Regex for number, where fixed whole part and unlimited decimal part

I am trying restrict whole part of number using regex to check for js and if not valid i truncate my number. I created my regex and test in regex online calculator, but it doesn't work in my component....
0
votes
1answer
27 views

Looking to generate a regex pattern for matching strings between backslashes

I'm looking to create an HL7 (type of message) parser. Part of that is being able to grab hex values which will appear as follows, with xxyy as single-byte hex values, xxyyzz as multi-byte hex values ...
0
votes
2answers
200 views

Regex for string but at least one character must be a number of letter [closed]

I have a lightning input component and I need the input values to be only alphanumeric characters, underscores and/or spaces. However, there is also one more requirement to have at least one number or ...
2
votes
0answers
25 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
188 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
64 views

Javascript Controller capitalize and remove accents [closed]

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
39 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
32 views

Regular Expressions - Regex for specific characters!

Which is the Regex for these symbols? -, –, %, /, ., "", «», '', ', <, >, &, :, (, ), !, ^, * Ι need to Replace them all with Space.
0
votes
0answers
17 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
44 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
101 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
67 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
37 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
52 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
61 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
259 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
68 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
47 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
35 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
133 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
81 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
30 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
98 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
1k 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
174 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
2k 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
445 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
235 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
86 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
97 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
186 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
413 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
114 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
36 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
362 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
79 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
94 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
160 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
958 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
52 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
33 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, ...

1
2 3 4 5