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
-
9
votes1
answer197
viewsif with a Matches or multiple comparisons?
Whereas I have a variable of the type String tipoResidencia that will never be null, and that I need to run a test, the default solution is this: if (tipoResidencia.equals("CASA") ||…
-
9
votes4
answers301
viewsHow to find hashtags in a string and store them in an array?
I have a content posting system on a particular social network of our company. When the user type the text with hashtags, I need to detect all of them and store them in an array. Example: Hi, I’m…
-
9
votes3
answers156
viewsRegular expression to reorder string
I have the result of a query with several joins, and in a row I have the concatenation of 2 groups. The line returns me a string as: 1,4|a1,b4. What I need is to regroup ID and Valor as follows:…
-
9
votes2
answers208
viewsScript for modifying Bible texts (accessibility)
I’m not a programmer. I research accessibility features based on my low vision. I am trying to develop a workflow that locates in the Bible texts standard "John 3:16" and transforms it into "John,…
-
9
votes4
answers1308
viewsWhat is the purpose of an empty parenthesis "()" in a regular expression?
Searching in Stackoverlow English about regular expressions, I came across a certain expression where it presents in the same an empty group (an expression in empty parentheses). Thus:…
regexasked 8 years, 9 months ago Wallace Maxters 102,340 -
9
votes5
answers1065
viewsRemove duplicated names with regular expression
Suppose I have the following vector, with the names of presidents of the republic: presidentes <- c("da Fonseca, DeodoroDeodoro da Fonseca", "Peixoto, FlorianoFloriano Peixoto", "de Morais,…
-
9
votes4
answers24927
viewsRegex - Picking text up to a given string
I would like to take the text up to the characters a) and if possible and separate responses also using Regex? pergunta pergunta pergunta pergunta pergunta pergunta pergunta pergunta pergunta…
-
9
votes4
answers150
viewsWhat regular expression to use to replace symbols in a string?
I got a string, just like "1x2,4÷4" and I want to replace the x for *; to , for . and the ÷ for / using the replace javascript. Which regular expression I would need to use to make this replacement?…
-
8
votes6
answers1639
viewsRemove an undetermined number of " " in a column in the database
The field description on the table product contains HTML generated by Ckeditor (English) that tries to escape the content: <table…
-
8
votes4
answers7006
viewsDoubt with Regex with new line
I created the following expression: "<strike>.*?</strike>" to get all the text taxed, but due to the source code having line break (as in ex. below) is not working. <p…
-
8
votes2
answers478
viewsHow do I get a loose number in my HTML?
Consider the following code: <span class="test"><span style="color:green">Teste</span>:</span> Text<br><br> <span class="test"><span…
-
8
votes3
answers1054
viewsRegex to select specific stretch
I need to identify within contracts the name information, CPF and address. The landlord’s line is as follows: LESSOR: Jose Reinaldo Lellis de Andrade RENTAL COMPANY: Isabel Cristina de Rezende Leme…
-
8
votes4
answers6348
viewsDetecting Line Break
I have the following function: if (str.match(/\d\d\d\d\d\.\d\d\d\d\d/)) { var codigo_velho = str.match(/\d\d\d\d\d\.\d\d\d\d\d\/); result = "1"; } How to change this function so it detects line…
-
8
votes3
answers3662
viewsFind quotes with blanks with Regex
I need to find errors where inside quotes have blank spaces at the beginning or at the end of them. Examples of errors: The news was given by " Jornal do Brasil". Paris is considered the "City of…
-
8
votes2
answers2526
viewsWhat is [QSA] and similar for in Rewriterule?
I have as an example the following RewriteRule ^(Home)?/?$ page/php/Home.php [NC,L] I know that the NC is Non-Case(Não diferencia maiúsculas e minusculas). L means that if a RewriteRule is true he…
-
8
votes1
answer72
viewsWhy does the Regex result have two values?
I need patterns kb, Mb or Gb, I’m using regular expression (k|m|g)b$ and it has to be at the end of the line. The test of my expression results in only 1 match when I test "20kb", but in this script…
-
8
votes2
answers500
viewsHow to use Regular Expression correctly
I’m studying about the RegularExpression, But I don’t quite understand. In my Model the property CPF must be filled in by numbers only: [RegularExpression(@"[0-9]", ErrorMessage = "CPF deve conter…
-
8
votes2
answers98
viewsNo need to escape the "." in a field [...] in REGEX?
I was looking at some regular expressions here on the network, and I noticed that in many, in the character field, the . was not escaped \.. Thus : [a-zA-Z0-9.]. He doesn’t need the character \…
regexasked 8 years, 11 months ago CypherPotato 9,292 -
8
votes2
answers1310
viewsHow to remove a word from a string without changing larger words that contain it
I would like to remove a word from a string in R. I was doing it as follows: > s <- "ele esta bem mas tambem esta triste" > stringr::str_replace_all(s, "tambem", "") [1] "ele esta bem mas…
-
8
votes3
answers15821
viewsREGEX - find expressions that DO NOT contain specific words
We are using REGEX to normalize pharmaceutical data from a string field and we need to distinguish very similar strings from an exception command. For example, in a very simple way, we have the…
-
8
votes1
answer2048
viewsWhat is the difference between replace() and replaceAll()?
I was reading the documentation to properly develop a mask and save without it. However I came across this doubt of methods replace and replaceAll for my string. What is the difference between the…
-
8
votes3
answers605
viewsHow to give a Regex before a string? And select?
What I need to do is this: let’s assume that the string is -> :. However I want to select "only" the string before the : using the Regex. To make it clearer: "select that word: another word here"…
-
8
votes2
answers12531
viewsCheck for special characters in a string using Regexp
I need to validate a password field that must contain at least one special character. Is there any Regexp expression to do this check? E.g. var patt = [a-z]; // verifica a existência de letras…
-
8
votes3
answers259
viewsNegative lookbehind only works on Google Chrome, is there an alternative to other browsers?
The regex /(?<!,),(?!,)/ has instability in some versions of browsers. I found this regex in the system of the company I work, and I didn’t understand very well the purpose of it. Apparently the…
-
7
votes4
answers1385
viewsHow to replace {vars} in a string?
I have a string string str = "Bem vindo {Usuario}. Agora são: {Horas}"; I want to replace {Usuario} by a name and {Horas} by the current time, how can I do this?…
-
7
votes4
answers1804
viewsShould I check dates with Datetime or regex?
I have seen two different ways to check whether a date is valid. In a "modern" way, with DateTime: $date="2014-02-04"; $dt = DateTime::createFromFormat("Y-m-d", $date); return $dt !== false…
-
7
votes3
answers1689
viewsHow to read file passing part of the name in Java
Example.: The name of my file would be 001nome.txt, this file will have a varying action on the name depending on the entity, ie one time it may be 001nome.txt another time it may be 999nome.txt.…
-
7
votes2
answers402
views"Variable system" with regular expressions
I have a file like this: %usuario: 'Anônimo' Olá <b>%{usuario}</b> (This is just an example and this is not the real case), but I believe that if I were to explain the real problem it…
-
7
votes2
answers483
viewsLike taking multiple groups in a Regex?
public string site = "http://www.tibia.com/community/?subtopic=worlds&world=Aurera"; private Regex nomedochar = new Regex("subtopic=characters&name=(?<player>.*?)\" >"); public…
-
7
votes2
answers917
viewsCheck if parenthesis has been closed
I need a Regex to check inside the string, the parenthesis has been closed. This is my example: /regex/.test("fdfdfdf(ddsd"); //retorna false, porque o parentese nao foi fechado;.…
-
7
votes2
answers2337
viewsHow to make "Replace" replace all occurrences of a word without taking uppercase or lowercase?
The function Replace supersedes all occurrences of a word or expression, but taking into account uppercase and lowercase: string str = "Hello WorLLd";//Substitui só os 'l' e não o 'L' str =…
-
7
votes1
answer117
viewsInclude tag in the first word of a string
I don’t have much knowledge of regex, so I got this rule ready. $break_title = preg_replace('/(?<=\>)\b\w*\b|^\w*\b/', '<span>$0</span>', $title); return $break_title; The problem…
-
7
votes2
answers4994
viewsHow to work with Regex on name validation?
I have tried in many ways to develop a Regular Expression that validates: maximum size of 60 characters can’t be a number cannot have accents, cedilla and punctuation the first letter of the name…
regexasked 10 years ago Nycolas Merino 103 -
7
votes3
answers400
viewsProblems with regular expressions (friendly url)
I’m having trouble reading the code of a particular product from a friendly URL. With the regular expression I put, it is accepting all the characters that are in front of the product code, ie…
-
7
votes2
answers1803
viewsHow to recover the number of characters via regular expression?
How to know the number of repeated characters (example: Goitobto = 2 letters to), consecutive characters (sequence of letters abc..) and consecutive numbers (example: 12345..) within a word, using…
-
7
votes2
answers5383
viewsHow to select all characters except some specific words using regex?
Good morning to all, I would like to run a string search for some specific strings, but in the project we are working on we have no access to any function find or similar, only to a regular…
-
7
votes3
answers1729
viewsRegex to find occurrences of one word before the other
I need to find in the system sources situations where Taction occur after Tdxbar. This will happen in different lines, but within the same file, for example: pnlVisao: TPanel; tbToolBar: TdxBar;…
-
7
votes2
answers207
viewsRegular expression start, end
I have two regular expressions: $exp1 = '/^abc.*\_20150430.txt$/' $exp2 = '/^def.*\_20150430.txt$/' Must return true for archives started by abc in the first and def in the second. In the two…
-
7
votes3
answers300
viewsRecover groups of a regular expression in Perl
I am running this regular expression to separate the digits of a version: ([\d]+)+ As you can see in this example, it works well enough to cover my needs. However, I have to add this treatment in a…
-
7
votes2
answers400
viewsuse regex in php explode function
I’m doing a query on my DB, and we can do an identical query on this: "hello world" "pacific ocean" What happens is that I can search for several strings at the same time: Expected result: String1:…
-
7
votes1
answer180
viewsDoes Regular Expression vary according to language?
Most languages have support for Regex (Regular Expressions) but, for example, Javascript does not have Negative Lookhead ((?<) , however already . NET Framework has virtually all functions of…
-
7
votes1
answer216
viewsUndefined error using replace()
I’m trying to make a sort of a people appointment, I made an attempt, but I was unsuccessful. Where is the error?? var nome =["Ana", "João", "Maria", "José"]; var frase = "@[1] é casado com @[0], e…
-
7
votes1
answer222
viewsWhy is there no Lookbehind in Javascript?
I hear there’s no such thing as group Construct lookbehind in Regex’s made in Javascript then I appeared some doubts as: Because there is no? Is there any reason that makes it incompatible c/the…
-
7
votes8
answers955
viewssplit/regex only on the first vertical bar "|"
I want to share the string in 2 parts (will always be a array divide into two parts - or two elements) each time a vertical bar | (only in the first case). For example: I have a string var string =…
-
7
votes2
answers103
viewsWhat does the expression "/ (?:(?:cats?|dog):)? /" do?
Doubt is as to the following regular expression: /^(?:(?:gatos?|cachorro):)?/ In understanding I have the following: Beginning: ^ ( ): This is a grouping, right? like (gato|cachorro|etc..)? Because…
-
7
votes4
answers147
viewsI cannot use Boundary( b) to validate a word starting with "@"
In the case of / b@MYVAR b/i, I cannot use Boundary, See: https://regex101.com/r/4bFElA/1 I need to validate a string that contains a @MYVAR word (Example). Are there any restrictions on this…
regexasked 7 years, 4 months ago LeonanCarvalho 3,527 -
7
votes1
answer182
viewsPython: is not turning my regex’s Character class into negative
I’m learning Regexes by the Automate the Boring Stuff w/ Python. In one of the titles of chapter 7, the book teaches about character classes. So far quiet. I have created Character classes for…
-
7
votes1
answer219
viewsHow to know the number of possible occurrences found by the group() method of the Matcher class?
After the question "Why does the Matcher class not return the number of groups correctly?", it was explained that the groupCount() actually returns the number of filter groups in the regular…
-
7
votes1
answer16562
viewsRegex inside SQL Server
How to recover fields with the following pattern? a111/1111 or a111_1111 or a111-1111 or a111+1111 where: a = some letter of the alphabet; 1 = any digit of 1-9; I rode a Regex that is working…
-
7
votes4
answers1976
viewsRemove numbers at the end of a Regex string C#
I have a string that contains the name of some records. Examples : string nome = "MARIA APARECIDA DE SOUZA MOURA 636598241"; string nome = "MARIA APARECIDA DE SOUZA MOURA 2018"; I would like to…