Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

-2
votes
1answer
31 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
76 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); ...
4
votes
1answer
42 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
19 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
23 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
111 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
33 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
55 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
128 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
365 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
34 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
30 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
115 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
59 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: ...
1
vote
2answers
821 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
556 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
30 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
89 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
473 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
31 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
92 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
312 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
149 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
149 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
40 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
604 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
35 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
225 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
65 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
2k 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
281 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 = ...
-1
votes
1answer
101 views

Unable to replace to “||” using replaceAll method

I want to replace Or, or, OR, oR to "||" validationExpr = validationExpr.replaceAll('(?i)or', ' \\|\\| '); The result will be &#124;&#124; How could we do this in Apex? Thanks
1
vote
1answer
385 views

How to find the exact match within a match

I am trying to match a credit card number using a regex. This is what I have: Pattern myPattern = Pattern.compile('(?:\\d[ -]*?){13,16}'); Matcher myMatcher = myPattern.matcher(strSource); while (...
0
votes
1answer
76 views

Adding an extra condition to a regex validation rule

I wrote a validation rule that specifies the amount of characters in the field and the way those characters are suppose to be placed. However to go with different wrtiting styles I want to be able to ...
0
votes
1answer
250 views

How to avoid System.StringException: No match found when only finding a substring and not a full match?

Preamble I know (based on this question "No match found" when using Regex in Apex), that I can avoid "No Match Found" by wrapping the results in: if(pm.matches()){ //Code } ...
0
votes
1answer
31 views

regular expression help

I need one regular expression pattern, in that i have to verify string contains at least one upper or lower case character or one number i dont have problem with position. if string contains only ...
1
vote
1answer
3k views

Regex including curly brackets

I have an e-mail processing class which takes the HTML content of e-mails, and stores them in rich text fields to be later rendered as PDF's to be printed via VisualForce. However, the e-mails ...
1
vote
1answer
614 views

Regex - Replace regex character with escape character in front of it [closed]

I am able to replace regex character to blank with the following code: str = str.replaceAll('\\p{Punct}', ''); System.debug(LoggingLevel.DEBUG, '***str: ' + str); Here is the reference that I got ...
4
votes
2answers
2k views

Regex Help- Escaping Characters And Matcher Method

I have a string: allPunctuation = '~!@#$%^*()_+|}{":?><`=;/.,][-\'\\'; This string contains APEX's way of escaping characters so I can include the ' and the \ characters. When I pass this ...
5
votes
1answer
208 views

Bug with parser in lightning bundle definition

If you are trying to define a regex in a helper for a lightning component for example and you try to do something like this simple regex to match a single /: var myRegex = /\//; or var myRegex = ...
0
votes
1answer
2k views

Regex for special characters validating digits [closed]

I have a regex pattern to confirm that at least one special character is used in passwords. The problem is it seems like it is validating numbers as well. In list below the third value though should ...
4
votes
2answers
3k views

Regular expression to check special symbols not working in lightning javascript

I have a validation function in lightning component that works on regex. I have a regular expression to check existance of special symbols but I am not able to save my js controller with that regular ...
0
votes
1answer
141 views

Regular Expression need to escape < br> [closed]

I'm using the following regular expression: (https?://(?i)www.|https?|www.)([A-Za-z\\d._~:/?#\\[\\]@!$&\'()*+,;=-]|%[0-9a-fA-F]{2})+[.][A-Za-z]{2,3} but for urls such as for instance: http://www....
2
votes
2answers
962 views

How to create SUBSTITUTE function formula using REGEX [closed]

I need to use a formula in Process Builder to populate a string field, and in this I need to replace all special characters with dashes. I've tried numerous ways but can't seem to get it right. What ...
1
vote
1answer
174 views

Replacing \n outside of quotes

I'am trying to parse a CSV but the column names contain new lines and I'am struggling to find a proper solution. If I have the following csv header for example: "Column 1 \n(this has valuable info)",...
1
vote
1answer
32 views

Need help with Pattern/Regular Experession [closed]

I want to check matching between string to string pattern that contain specific character as any. For example: Assume string pattern is: "TEST ***ING NUMBER *" For input: "TEST STRING NUMBER 1" ...
1
vote
1answer
230 views

Why does my REGEX for website validation not work?

I have the expression working correctly here: http://regexr.com/3gemo I tried converting it to a validation rule in Salesforce but the following doesn't even save and keeps throwing a 'Syntax error': ...
0
votes
1answer
471 views

Regex Search-and-Replace with Capture Groups?

In IDEs a common operation is to perform a search and replace operation using a regex pattern in the search field and another pattern with capture groups in the replacement field. For example, I can ...
1
vote
1answer
274 views

Regular Expressions - Pattern and Matcher with roups

I have input string to process of the format xxx:xxx:xxx:xxx:filters:6:item:xxx Where xxx could by any combination of alphanumerics and underscore. I am trying to capture the number between ...