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
1 answer
46 views

Regex not working in class but works in execute anonymous

You can get some context here on my previous post. When I run the below code on execute anonymous, it renders the following result: String txt = 'Requesting service for Id Number 9202204720082, Case C ...
  • 1,357
0 votes
1 answer
37 views

Regex for Case Number, South African Id and Passport

Please bear with me, I'm not well versed with Pattern, Matcher or Regex. I found the below on https://regex101.com/ South African passport: [A|D|M|T][0-9]{8} South African Id: (([0-9]{2})(0|1)([0-9])(...
  • 1,357
2 votes
4 answers
198 views

REGEX in Salesforce Flow to retrieve a substring

I need to retrieve a substring from a text field in a flow. is it possible by using regex instead of apex ? If i try this regex i receive false as result ( boolean ), i should get true and then i ...
2 votes
1 answer
62 views

Validation Rule not running the whole formula

A field(Example__c, Text 255 char) can have a value of alphanumeric(numbers and/or letters) type and character length should ONLY be either: 3 character value 7 character value 12 character value I ...
-1 votes
1 answer
20 views

REGEX for combined alphanumeric ONLY strings of indeterminate length

We have an integration that is failing when special characters are included in certain text fields. I found NOT(REGEX(fieldName__c, "[a-zA-Z0-9]")) which works fine for a single character/...
0 votes
2 answers
32 views

String split on newline creates blank strings for every newline

I have a split on a newline which works fine, but it seems to create a blank value for every time it does a split, so 'MyText' contains the following values, separated by a newline: Blue Green Yellow ...
  • 1,455
0 votes
0 answers
39 views

Need help in Javascript while using it in LWC with RegEx Salesforce

I need help with the below problem. I feel I have half the answer but the remaining half is the key. I have variables in JS and respective values in them: this.A => 'Name = Joy' this.B => ...
0 votes
1 answer
57 views

Regex / Pattern, Matcher - Exclude a specific Match

Related to the matching of IBAN Numbers: Given this regex pattern ((?:DE)[0-9]{20}) is there a way to exclude specifically the IBAN Number e.g. DE02120300000000202051 directly in the regex pattern or ...
0 votes
0 answers
33 views

how to use a variable in a reguar expresion in apex?

I am using the following to parse the data of the Telefon from my description field in the case in Inboundemailhandler. Pattern urlPattern = Pattern.compile('(Telefon)\\W*\\d*'); Matcher m = ...
  • 73
0 votes
0 answers
17 views

Regex for the field validation

I have created a Regex expression for the custom object's custom field Worksite_Street__c and Worksite_Street_2__c that can only contains number, alphabet (small and capital) and #,'-:_@/(). these ...
-1 votes
1 answer
48 views

create a validation rule that ensures either a single email or a multiple emails are comma separated with correct email format

I created this Regex and tested it on online regex tester. But when I am using the same regex in salesforce validation rule then I am unable to save it due to "Error: Syntax error" The Below ...
0 votes
1 answer
153 views

Regex to find dd/mm/yyyy

I have a pretty simple code and in one case it works, and not in all the case, I wanted to know what I'm missing I'm trying to match a date in this format dd/mm/yyyy This is my code: String d = '20/03/...
  • 145
0 votes
1 answer
33 views

REGEX too complicated in breaking a soap API response

I am working on an apex class that makes a soap API callout and receives a response. To see the complete response in debug logs, I am using a splitString() method to break down the XML response at nth ...
-1 votes
2 answers
45 views

Extract data from string and reframe it into another

I have got a string in below format: String test = '11, -22|32.45, 34|32, 41|32, 12.12'; I am trying to convert it into below format: {"a":11,"b":-22|"a":32.45,"b&...
-2 votes
1 answer
495 views

Regex for US Federal Tax ID (EIN) [closed]

In the pattern attribute of an input tag, I am using the following regular expression for validation of the US Federal Tax ID field. pattern="^[1-9][0-9]{8}$" But this regex allows ...
0 votes
1 answer
148 views

Compilation of Regex in Apex

I am trying to compile following regex /^[~`!@#$%^&*()_+=[]{}|;':",./<>?a-zA-Z0-9-\w\s]+$/ String fileNameRegex = '/^\[~`!@#$%^&*()_+=\[\]\{}|;':",.\/<>?a-zA-Z0-9-\w\s\]...
-1 votes
1 answer
257 views

Contains or Regex in formula for checking multiple values

I'm writing a formula to check of a field (for example, "Country"), contains one of many values. Example: CONTAINS(“Massadonia Republic:Dominican Republic:US:UK”,Country) From what I'm told ...
0 votes
1 answer
75 views

Pattern.quote matches substring instead of whole word match

I was trying to implement a case insensitive whole word searching pattern. I came up with the following pattern: Pattern p = Pattern.Compile('(?i)'+Pattern.quote('af')); Using it in the code below: ...
3 votes
1 answer
379 views

Regex to match single to double digits

I am trying to replace all digits with {digit}, but the issue is double digits are getting replaced incorrectly. For eg: String str = '1 AND 2 OR (3)'; Pattern p = Pattern.compile('([0-9]+)'); Matcher ...
2 votes
2 answers
382 views

RegEx pattern matcher issue

I'm struggling with a "simple" RegEx problem. I wan't to check a sting if the pattern "BN123456" or "bn123456" is included and if so, extract it. The pattern could be in ...
0 votes
1 answer
654 views

Aadhaar card validation rule not working using Regex in salesforce

I'm basically having validation rule in salesforce to check the whether entered value is in required format or not. However in below formula validation formula for Pan Number is working fine but for ...
2 votes
1 answer
202 views

Regular Expression is matching non-whole words despite leveraging \b within the expresion

I am having a regex replace issue where the regex statement is matching non whole words. In the below example I have the word 'cormand &'. When I run the regex statement, it return 'corm &'. I ...
0 votes
1 answer
131 views

Pattern Matcher problem

I want to get the sub string 'fact.cm_comp_sales_adjustment_factor__c.living_area_default_index_score__c' in the string '[subj.cm_parcel__c.sqft__c]+[comp.cm_sale__c.sqft__c])*fact....
0 votes
2 answers
1k views

Regex for Email List on Salesforce Validation Rule?

**UPDATE 22 June 2022 For simplicity sake, I will edit my question to have emails separated with just semicolon e.g. 213@aaa.com;424@www.com So I have this Long Text Area field to capture multiple ...
  • 1,175
0 votes
1 answer
1k views

How to validate Mobile Number with Country code followed by 10 digits

I am new to salesforce . I have MobilePhone field in Contact. I need to validate the MobilePhone Field such that it must include (+1, +91, +355) followed by 10 digits mobile number. NOT(REGEX(...
1 vote
1 answer
52 views

How to optimize Searching bulk data for list of words

I have a spam detection mechanism which searches strings of word in posts. The List can be 500+ entries long sometimes. I have a naïve searching algorithm //Unnecessary logic have been removed public ...
0 votes
1 answer
588 views

Regex for Lightning Input in Aura Component

I have one Lightning input in which I have to show the error message if condition is not satisfied. 1.4 characters min 2.12 characters max 3.Allowed characters: Letters (A,B,M....26 capital letters of ...
1 vote
1 answer
364 views

LWC issue with replacing first invalid character

In my LWC, I have a text input where I need to prevent the user from entering anything besides a number or a decimal point. The Javascript function I'm using does replace the invalid characters with ...
0 votes
1 answer
333 views

Salesforce Regex - Return List of Matches

I have the following String: "Trastuzumab IV (Herceptin): Request change to Trazimera or Monoferric" I am using the following regex: (?<!\()\b(Trazimera||Monoferric)\b(?![\w\s]*[\)]) I ...
0 votes
2 answers
3k views

Removing leading zeroes in Date String

I have checked a number of posts and regex examples but for some reason I can't get the leading 0's to be removed from the date string below. Can anyone see what I am doing wrong? wanted result: 4/6/...
  • 3,329
0 votes
1 answer
2k views

How to exclude Test files From Searches in VS Code?

Is it possible to exclude test files when doing a grep search in VS Code? I would have thought one of these regexes would have worked ^/(?!Test$)[a-z0-9]+$ Or ^/(?!Test)([a-z0-9]+)$
0 votes
1 answer
118 views

Regex Pattern to Locate first instance of Email response - On ..... wrote:

I have a field to store the Latest Comments on a Case. For email responses I would only like to store the current email response and not all of the historic replies. Most of my email responses are ...
0 votes
1 answer
152 views

Unable to match group in apex regex

I am trying to dynamically match a string against other string. String badWord = 'badwords'; String comment = 'I talk badwords and goodwords'; Pattern MyPattern = Pattern.compile('((.*)('+badWord+')(.*...
-1 votes
1 answer
68 views

Formula to strip images from Chatter Posts [closed]

I am building email notifications from Chatter Posts. When the Post is created my notification Flow is writing the Feed Item Body to a Rich Text field on my Case which is included in my email. If ...
0 votes
2 answers
241 views

Best practices for sanitizing string data with AMPScript

I have a CloudPage with a form consisting of a text field. When the user submits on the form, the text field data is captured within a parameter and posted for processing on another Cloudpage. The ...
  • 13
0 votes
1 answer
709 views

How to stop replacing single quote ' in apex with space

I am trying to replace all characters expect below mention characters with space in Apex [A-Z a-z 0-9-,.&/'@()+# $: ] String customerName = jo&hn<>ji'o; String AccName = customerName....
0 votes
0 answers
23 views

SSJS RegExp Are Broken? [duplicate]

The Regular Expressions in SSJS Email Studio seem to be broken or have different results than expected, Is anyone able to shed some light on this discrepancy and how I can work around this? Thank you. ...
user avatar
0 votes
1 answer
340 views

How to use lookup fields using RegExp for search bar in LWC data-table?

Here's the link to the similar question How to filter Data in dataTable lwc based on the input in search bar? The above works fine with non-lookup fields but doesn't seem to be working in my case. If ...
1 vote
0 answers
308 views

Replace whitespace in part of a string

I have cases which contain urls in the case description, and the urls contain whitespace. I need to replace the whitespace with %20 in order to make the links clickable from the case. Obviously the ...
  • 13
0 votes
1 answer
173 views

Matcher.matches() is not working as expected

I am trying to match DateTime input using the Pattern and Matcher class of Apex but wasn't able to achieve it. I've created a regex for matching the Datetime input as follows and it matches the ...
0 votes
0 answers
89 views

Validation rule on user input

I'm trying to restrict users of filling in certain values in a VAT field. I want them to follow the VAT convention PREFIX-NUMBER(ex. BE0121569515) I made a validation rule to restrict on character ...
  • 113
0 votes
1 answer
931 views

Regex Validation Rule Help

Looking for help on correcting my validation rule on a First Name field. We want to allow A-Z, a-z, and then also allow apostrophe, hyphen, and period ('-.) When testing my formula below, it allows a ...
  • 51
1 vote
1 answer
364 views

Apex Pattern, match everything (including new lines) between 2 passed parameters?

I'm trying to get a substring from a block of text that can contain new lines. Whats the regex needed to capture everything including newlines between 2 strings thats are passed in? The regex below ...
-2 votes
1 answer
134 views

Regex Pattern not working

I not want the user to add the symbols in the opportunity column. I implemented the validation in the validator. But it is not working. NOT(REGEX(Account_Name_CAD__c", "^[#$%^&*+=-_/>&...
1 vote
1 answer
606 views

Input Field Not Updating after calling .replace()

I have an input field on an LWC that should only accept numbers in the range [0-9]. I have a regex and a replace method. But the invalid characters only get removed after I enter a valid one. I could ...
0 votes
2 answers
69 views

Not able to use the regular expression in Survey response validation - ^\d+(\.\d{1,2})?$

I am trying to add a validation in Salesforce survey response. User should be able to enter numbers up to 2 decimal places. Allowed inputs, 12 12.3 12.34 I am trying with ^\d+(.\d{1,2})?$ but I am ...
0 votes
1 answer
112 views

Match the substring in a string and append the substring with #tags

I have a string in that match the substring and append the substring with #tag like #Test#; String str = 'This is a TesT for reteSt the tEsTing which will confirm that test was not TEsTed perfectly by ...
0 votes
1 answer
150 views

How can I get "pattern"attribute from component (html) to Controller (javascript)?

How can I get "/ˆ[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,6}$/" in the Controller class? <label for="clientEmail">E-mail</label> ...
  • 123
0 votes
1 answer
624 views

Not able to remove substring that is variable from a string

I want to remove everything except for Name. removeStart() and remove() don't seem to take variable as a parameter. String tmpField = '{!Contract.Name}'; String child = 'Contract'; tmpField = ...
0 votes
1 answer
939 views

String.split() regex with colon

I'm trying to parse a set of questions and answers that are being written to a large text field in the following format Q1: question 1 A1: answer 1 Q2: question 2 A2: answer 2 etc... I want the ...

1
2 3 4 5
7