Most voted "regex" questions
Use this tag when the question refers to some resource, information, or problem relating exclusively to regular expressions. Regular expressions (usually abbreviated as "Regex", "regex" or "regexp") are a declarative language used for matching patterns within strings. When asking, also include a tag specifying the programming language or tool you are using to identify one of the different dialects.
Learn more…1,253 questions
Sort by count of
-
55
votes5
answers52381
viewsRegular expression to detect credit card flag
I need Regex to detect when the credit card flag is Hipercard, Aura and Elo. I already own regexes for Amex, Martercard, Diners Club, Visa, Discover and JCB: Visa: ^4[0-9]{12}(?:[0-9]{3})…
regexasked 10 years, 9 months ago jonathanrz 653 -
49
votes4
answers120536
viewsRegular expression to validate a field that accepts CPF or CNPJ
I have a <input> on the form that must accept CPF or CNPJ. I will use in the back-end in PHP the value to save or in the field "Cpf" or in the field "cnpj" of a table in the database. I’m…
-
34
votes7
answers87300
viewsHow to validate with regex a string containing only letters, whitespace and accented letters?
I’m looking to validate one input text for full name in order to accept only letters, blank spaces and accented letters. Valid formats: Leandro Moreira leandro moreira Kézia Maria kezia maria Cabaço…
-
32
votes7
answers58283
viewsRegular expression for e-mail validation
I am trying to create a regular expression to validate any e-mail, I wrote the expression below, but it is not working as expected: var parse_email = /^[a-z0-9.]+@[a-z0-9]+\.[a-z]+\.([a-z]+)?$/i;…
-
29
votes5
answers69449
viewsHow to make a regular expression for mobile phone?
How to create a regular expression to validate the phone field you accept 99-99999999 (DDD + 8 numbers) or 99-999999999 (DDD + 9 numbers). And that when typing it add the dash - automatically!…
-
28
votes2
answers8284
viewsWhat does the REGEX shortcut mean?
I see a lot of people wearing \s in regex thinking its meaning is ' ' (space) because I tell you, it’s not, at least not only that. But then what does the \s in REGEX?…
-
27
votes2
answers576
viewsWhy shouldn’t Regex be used to handle HTML?
I understand that if I try to use Regex over HTML, HTML tags will drip from my eyes like liquid pain, among other horrors. And that I should use an XML parser or something like. My curious child…
-
26
votes2
answers534
viewsWhat can make a regular expression slow?
It’s happened here in the Stackoverlow I am recommended by some users to avoid the use of regex, in some cases as it may have undesirable performance. I have also heard that, depeded in the way that…
regexasked 9 years ago Wallace Maxters 102,340 -
24
votes5
answers1499
viewsWhat is a gluttonous regular expression?
What is a Expressão Regular Gulosa? What sets her apart from Expressão Regular Não-Gulosa? Expressões regulares Gulosas consume more resources than Não-Gulosas?…
regexasked 9 years ago Wallace Maxters 102,340 -
24
votes2
answers665
viewsWhat is a regular expression?
In many codes I see functions with a set of special characters that seem to have a function of their own. I see it in virtually every language, so what is it after all, a class, a library or what…
-
23
votes1
answer1194
viewsRegular expression to recognize language: words that do not contain "bbab"
The @LINQ challenged me to write a regular expression to recognize the following language L: I was able to assemble, on this premise, the following finite state machine: the Miguel Angelo detected a…
regex mathematics computer-theory automata formal-languagesasked 7 years, 1 month ago Jefferson Quesado 22,370 -
20
votes1
answer422
viewsIs replacing strings with Regex slower than Replace()?
Let’s say I want to do something like this question: How to convert Camelcase to snake_case in C#? You had some answers, but I want to highlight these two. Answer 1 string stringSnake =…
-
19
votes4
answers1173
viewsWhat does the regular expression "/(?=(?:...)*$)/" do in detail?
I just needed a solution to put points to separate numbers from three to three, backwards. For example: 1000 => 1.000 100000 => 100.000 10000000 => 1.000.000 In a reply I found in English…
-
18
votes7
answers44529
viewsHow to get only the numbers of a string in Javascript?
I wonder if there are functions that return only the numeric values of a string, if there is not, what is the simplest and efficient way to implement? Example: apenasNumeros("5tr1ng"); Upshot: 51…
-
18
votes2
answers6538
viewsMeaning of ?: ?= ?! ? <= ? <! in a regex
In several regex I noticed some symbols that do not seem to be part of the capture but some kind of functionality. I would like to know the name or term of these symbols and what is the…
-
18
votes3
answers11309
viewsHow to delete duplicate spaces in a string?
I have the following string: var str = "00000.00000 111111111.111111111111 33333333" I need to remove the extra spaces for it to look like this (only with 1 space): var str = "00000.00000…
-
18
votes3
answers4338
viewsWhat is the "line break" in a Regex?
The language I use is R. And, as the theory of Regular Expressions suggests, each language deals differently with line breaks (\n). Consider the following string: text_1 <- c('Olá, meu nome é…
-
17
votes3
answers960
viewsHow to find a String from Regular Expressions
I have a field in the SQL Server 2014 database that stores the client address. The problem is that everything is stored in a single field varchar. Here are some real examples: Antonio José Nerchis…
-
17
votes2
answers311
viewsRegular expression to detect nested structures in a template
I’m trying to create a template engine using Javascript. The syntax will be more or less similar to that of Laravel (Blade), with some modifications. I’m at the part of creating the expressions. The…
-
16
votes5
answers19971
viewsValidate regular expression name and surname
I need to create a regular expression that validates whether the format of the user’s name and surname is valid, for example: Maria Silva | true Maria Silva | false Maria silva | false maria Silva |…
-
16
votes1
answer413
viewsHow does "positive" (?=X) work combined with "positive" lookbehind (?<=X)?
After answering this question, and despite can understand what is happening in the regular expression of my reply, I was curious to know how the excerpt ((?<=;)|(?=;)) works. I read in this reply…
regexasked 7 years ago user28595 -
16
votes1
answer250
viewsDifference between the greedy ?? and *quantifiers?
I have these strings: x <- c('ondasffasf', 'ondassn\nlld', 'ondas', 'ond', 'ndasss', 'das') And this code with ??: library(stringr) str_extract(x, regex('ondas??')) [1] "onda" "onda" "onda" NA NA…
-
15
votes3
answers17342
viewsHow to use more than one separation character in the split() method?
I’d like to break a String in various substrings, for this I am using the method split(). Turns out, I’m not sure which characters might be in the variable I use. Exemplifying: String words[] =…
-
15
votes1
answer1975
viewsWhat good is a Fatherland ( b) in a regular expression?
A long time ago, I took a look at the use of Boundary, studying about regular expressions in PHP (PCRE Patterns). I came across the \b (which is called Boundary). What is the use of it in a regular…
regexasked 8 years, 9 months ago Wallace Maxters 102,340 -
15
votes2
answers321
viewsHow to emulate the regular expression reset branch in Java
I have this regex: Pattern p = Pattern.compile("(?:([aeiou]+)[0-9]+|([123]+)[a-z]+)\\W+"); Basically, it has the following parts: one or more lower-case vowels ([aeiou]+), followed by one or more…
-
15
votes1
answer229
viewsIs a finite state machine capable of detecting the primality of a number?
I recently saw a publishing how they taught Perl to recognize a prime number using regular expressions. The regular expression in question is: /^1?$|^(11+?)\1+$/ The only requirement of this regular…
regex mathematics computer-theory automata formal-languagesasked 4 years, 8 months ago Jefferson Quesado 22,370 -
14
votes2
answers288
views -
14
votes3
answers262
viewsHow to validate strings?
I have the following strings: www.adorocinema.com/filmes/filme-226616/fotos www.adorocinema.com/slideshows/filmes/slideshow-124792 www.adorocinema.com/noticias/filmes/noticia-125494…
-
13
votes3
answers4221
viewsTake only the values before the character "=" using regular expression?
I have a file containing the following contents: Maringa=123123 Marialva=789789 Mandaguacu=123456 Cidadex=A341a2 How do I pick up only the characters before the =, using regular expression? I tried…
-
13
votes3
answers1511
viewsHow can I replace a part of a string by itself plus the "~" character?
How can I replace a part of a string by itself plus the character "~"? I’m doing it this way: only when the string has two equal numbers as the 51 that comes just after AP and the contained in the…
-
13
votes3
answers343
viewsRegular Expressions: Lazy quantifier function "?"
I have learned about the use of Regular Expressions and read some explanations about the use of the sign ? (called Lazy quantifier), as in this Microsoft documentation: *? : Corresponds to the…
-
12
votes4
answers6231
viewsHow to select a text snippet in a String?
I’m creating a text file and using some delimiters (<# and #>) I need to select what’s inside the delimiter <# texto.delimitado #>. Using the function split() javascript. What would be…
-
12
votes2
answers372
viewsHow to create regexReplace for a delimiter?
I have the following content: 123|321|1234\|56\|teste\||123 I’d like to make a regex replace to replace all | by line break and ignore the | escaped with \, this way I would like to get the…
-
12
votes1
answer100
viewsHow to define Titlecase using regex in Javascript?
I have this Function: var titleCase = function(s) { return s.replace(/(\w)(\w*)/g, function(g0, g1, g2) { return g1.toUpperCase() + g2.toLowerCase(); }); } If I call her by passing something she…
-
12
votes3
answers1178
viewsWhat is the difference in use between the Matcher() and find() methods?
I’m trying to understand the difference in the use of these two methods of the class Matcher, but I couldn’t understand it from the description of the documentation that says: public Boolean…
-
12
votes2
answers295
viewsHow to create a simple markdown with PHP?
I would like to create a simple markdown, for bold and italic for now only, for example: **foo** flipped <b>foo</b> __bar__ flipped <i>bar</i> Of course some details are…
-
12
votes2
answers944
viewsHow do I find a character pattern corresponding to a date in a text?
I have a text in a string, and I want to use some method, like the .find, to find a string in the format "dd.mm.yyyy". I thought I’d use .find("xx.xx.xxxx") but I don’t know what to put in place "x"…
-
11
votes1
answer215
viewsWhy use a regular expression "compiled" (re.Compile) in Python?
In a another question of this site, I noticed that although the two responses made use of regular expressions, different paths were taken: One of them used the function re.search to carry out the…
-
10
votes2
answers3444
viewsHow to count the amount of occurrence of a substring within a string?
I have the following return: EXCEPTION,Classexception,EXCEPTION, I’d like to take the amount of times that String appears EXCEPTION using Regex. I used the following code:…
-
10
votes3
answers7149
viewsClear ZIP code with Javascript
How to clear the formatting of a zip code field in this format: 87.678-000? I need to take out the "." and the "-" and return only the numbers. I tried something like, unfortunately it didn’t work.…
-
10
votes2
answers1689
viewsFind <tr> Element of a certain content
I would like to know how to find a certain element <tr> in a numbered table. For example: In a table where each row <tr> has its cells <td> numbered 1-5, containing 4 lines…
-
10
votes3
answers15565
viewsWhich regular expression can I use to remove double spaces in Javascript or PHP?
What regular expression can I use to remove excess white space? I mean, leave them with the amount of normalized spaces. Example Of: $string = 'Estou no Stack Overflow em Português '; To: $string =…
-
10
votes4
answers209
viewsHow to capture textarea tag with new line?
How to get the values of a <textarea> with Regex, including new line? I have the following expression to get a textarea: ([<]textarea.*[<\/textarea][>]) Online example. The problem is…
-
10
votes4
answers3526
viewsHow to pick a String that is between Javascript tags using Regex
I have the following string: var text = "Meu nome <[email protected]>"; I’d like to take just the [email protected], using Regex.
-
10
votes2
answers1420
viewsHow to split a String that contains white spaces at the beginning?
For the problem in question, I need to remove all the special characters and spaces and count the new possible outputs. My intention is to separate the string with the method split(). For this,…
-
10
votes3
answers789
viewsHow is a REGEX Javascript for Mail Tracking Code (AZ123456789AZ)
I need a Regex for the A-Z 1-9 A-Z standard validating AZ123456789AZ I’ve tried to /^[[A-Z]{2}[1-9]{9}[A-Z]{2}]/$
-
10
votes2
answers908
viewsCapitalize Javascript text, ignoring abbreviations
I have a Javascript code to capitalize text that treats some exceptions. However, I would like to address a few more, such as ignoring abbreviations, which would be to have a point before or after…
-
10
votes2
answers230
viewsWhat does the / +/g parameter mean in the . split() method?
Can anyone explain to me what the parameter means / +/g within a method .split()? var message = "-lucas o p i "; var args = message.slice(1).trim().split(/ +/g); var comando =…
-
9
votes3
answers763
viewsHow to list the results of a regex search in a directory?
I have a directory with some C#files. In these files there are several SQL query codes. I need to list all SELECT commands in these files using Powershell. The commands start with SELECT and end…
-
9
votes2
answers1726
viewsHow to replace multiple using variable as first parameter?
When I want to replace all occurrences of a string I do so: var ola= "ola mundo ola mundo"; ola = ola.replace(/ola/g, "xxx"); Result: "xxx world xxx world"; But I want to use a variable instead of…