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
-
7
votes3
answers331
viewsHow to make this regex?
I have some difficulties using REGEX, so I would like help to separate the following text, example: 1ª Temporada - Nome da temporada 01 - Nome do ep um 02 - Nome do ep dois 03 - Nome do ep três ...…
-
7
votes3
answers816
viewsRemove spaces from a string from the second occurrence
Currently I am removing spaces using a simple replace() and adding a space I must preserve between the third and fourth character using substr() let str = 'abc defghijk lmnop qrstuv wx y z' str =…
-
7
votes3
answers4852
viewsHow to remove accents with regular expressions in Python?
I am developing a regular expression to try to replace accents and characters with normal characters Example: á = a ç = c é = e But mine regex is just eliminating some hint? import re string_velha =…
-
7
votes1
answer73
viewsLimiting the number of regex Matches with Python
I’m having a little trouble, I’d like to create a for in the Python to return a specific amount of match of regex. The way I did, he’s returning all the links that exist and that meet the defined…
-
7
votes2
answers175
viewsRemove HTML snippet between specific comments
I have a class called Page(page.class.php) that "mounts" the page, and one of the functions of that class is to censor content by user level. <?php class Page(){ //(...) static function…
-
7
votes1
answer68
viewsWhy is there result divergence depending on how the regular expression is executed in Javascript?
What is the reason for the result divergence found when executing the same regular expression in different ways in Javascript? Regular expression:…
-
7
votes2
answers141
viewsHow to Split by Capital Letters and Numbers at the same time?
How can I separate a string by letters and numbers at the same time? For example if I have strings: composto1 = 'H2SO4' composto2 = 'CaCO2' composto3 = 'C20H17' I’ve tried to do: import re…
-
6
votes4
answers3090
viewsRegex for Cifras site as Cifraclub
I need a Regex that works well, and in JS, to take only the chords of a cipher like this: http://www.cifraclub.com.br/gui-rebustini/sou-um-altar/ The problem is I never messed with Regex. Any idea?…
-
6
votes3
answers331
viewsUnknown cause error: "Syntaxerror: invalid range in Character class"
Situation: I have a page that contains a <iframe> another, on this other page, I have a simple HTML element input: <input type="text" required="" pattern="[a-Z]{2,35}" tabindex="6"…
-
6
votes3
answers5650
viewsRegular expression to pick up the value after the comma
With the following expression (,)([0-9]*) manage to catch the ,25 but would like to catch only the 25. decimal (10,25) In this case how can I disregard the ,…
-
6
votes2
answers1446
viewsRemove String Connectors with Regular Expression
How could I remove connectors: "e", "do", "da", "do", "das", "de", "di", "du". From a sentence without changing the whole name. Example the name: Daniela de Andrade. I wanted to remove only "from",…
-
6
votes4
answers361
viewsDecrease span field value with preg_replace
I am trying to change all the values of the fields it contains span class. Example the site is like this: <div id="isOffered"> <a class="price addBetButton footballBetButton"…
-
6
votes3
answers233
viewsSubstitution of variables in the body of the message
I am creating a message profile system, when the system performs a certain action it picks up a certain profile and triggers the message as e-mail, however I would like in the body of the message,…
-
6
votes2
answers338
viewsComments on regular expressions?
REGEX is a very complicated language and not easy to read, but is there any way to describe what that little letter does? Example: Nessa regex: \{.*?[^\}]+\} will capture everything you have in a…
-
6
votes2
answers766
viewsWhat is 1 for in regular expression, in javascript?
I was taking a look at this @Sergio response here at stackoverlow: /a/93995/4995 There was an excerpt of code like this: /^(\d)\1+$/.test(111) What exactly does the \1 in that regular expression?…
-
6
votes2
answers704
viewsError replacing occurrence in string using replaceAll
I extract the text from several lines of a PDF, at the beginning of each line I have a configuration of the font size and family used on that line, but then I need to remove this information. First…
-
6
votes2
answers1457
viewsDoubt, java regular expression
I have the following regular expressions. The first one validates words and is right. The problem is the second one is to validate directory, for example…
-
6
votes3
answers1209
viewsGet the name of the Image in the URL
I need to get the name of the image in the url. /data/data/com.intel.appx.IZICondominios.xwalk15/files/_pictures/picture_006.jpg I need you to come back: picture_006.jpg The URL template is not…
-
6
votes5
answers1021
viewsPick first name with Regular Expression
I need to get the first name with regular expression, only I’m not getting it right. Today I use the code like this: <?php preg_match('/[[:alnum:]]+/i', 'Alisson Acioli', $matches); return…
-
6
votes2
answers435
viewsMultiple regular expressions in a bar string
I need a regular expression that matches the end of a URL in the following format: /somente-letras/somente-numeros[/] To match the part of somente-letras, I used ~^/[A-Z]+$~, but from the moment I…
-
6
votes3
answers82
viewsHelp with Regex
Before asking I looked for several references, but still do not understand much and I managed to get only to a certain point. My goal is to validate that a string specific has 10 characters, the…
-
6
votes3
answers154
viewsDoubt Normalizer + Regex
Could someone explain me the code below? returnStr = Normalizer.normalize(returnStr, Normalizer.Form.NFD) .replaceAll("[^\\p{ASCII}]", ""); returnStr has as initial value a url.…
-
6
votes1
answer981
viewsreplace all occurrences of a character in a javascript string
I need to replace all occurrences of these 2 characters "_1" in a string with "_2", but Regex does not accept to put a variable there. var current_registration_number = 1; html =…
-
6
votes3
answers68
viewsregex Return false?
console.log(rule); // rule = max18 // rule = max120 // rule = max6 var pattMax = new RegExp('^(max).(\d{1,3})'); pattMax.test(rule); //false? if(pattMax.test(rule)){ console.log('é max seguido de 1…
-
6
votes1
answer172
viewsCheck string Regex C#
I have a string that can only be composed by X capital and by -. Example : X-XX-XX or else X-X-X-XX-XXX. Where each - a group would be counted and each X one digit. Example 1: the string X-XX-XX has…
-
6
votes1
answer117
viewsRegular expression to swap the variable pair in mysql in PHP file
Which expression can I use to exchange MYSQL function parameters, example: mysql_query($query,$db); mysql_query($db,$query); Why I look for mysql_query and change to mysqli_query after I can make…
regexasked 7 years, 4 months ago Rodrigo Luan 385 -
6
votes1
answer571
viewsVBA Regular Expressions - Extract substring
In the text below, I would like a regular Pattern Expression, compatible with VBA, to extract the text located between the equal sign "=" and the first line break (highlighted in bold): Client = CON…
-
6
votes2
answers593
viewsAND operator in regex
I have the following date/time format: 25/01/2017às11:53:37 And the following regex: REGX_DATAHORA_DISTRIBUICAO = "(?<data>\d{1,2}\/\d{1,2}\/\d{4})|(?<hora>\d{1,2}:\d{1,2}:\d{1,2})"…
-
6
votes5
answers2539
viewsRegex to check if string does not end with certain characters
I’m racking my brain on the website http://www.regexplanet.com/advanced/java/index.html I’m trying to make a regex that validates some .txt not containing the characters JJ or M3 at the end of the…
-
6
votes3
answers2884
viewsREGEX - Capitalized words in the middle of the sentence
Is there any regex/replace to uppercase words in the middle of the sentence to lowercase? (Yes, I could pass everything to Lower) but there is a catch, the rule should be ignored if the word is…
-
6
votes4
answers409
viewsSeparate text by space except inside quotation marks
I’m trying to use a regex to separate the texts separated by space, except those inside quotes, for example: Entrada: texto1 texto2 "texto3 texto4" texto5 Saida: Array("texto1", "texto2", "texto3…
-
6
votes2
answers2983
viewsHow to exclude a certain group from the regular expression
I have a tax file that comes with the following information on the line: Ex:. OCF|DINHEIRO|160.12|12 To fix it I have to erase a part, and the right one would be: OCF|DINHEIRO|160.12 Then I started…
regexasked 6 years, 5 months ago Marcos Correia 123 -
6
votes3
answers62
viewsBest way to apply a Pattern to the acronym
I have the following possible returns: AB A1 To The first will always be a letter, the second may or may not occur and may be letter or number. In Javascript it looks like this (Example): if…
-
6
votes2
answers386
viewsRegular expression C# console application
I have a list of words, for example: São Paulo 9000-000 a 9999-9999 Barigui 8000-0000 a 8999-999 I want to take only the numbers, with the same trace and separate, in another list for example, I…
-
6
votes3
answers1491
viewsMYSQL and REGEX Phone Number
I need to select records that have in the middle of the phone numbers text to delete (automatic moderation). It’s a forum, people every day comment and put phone numbers in the middle of the…
-
6
votes2
answers640
viewsHow to allow white space in any part of the sequence in a regular expression?
I have a field that accepts at least 12 alphanumeric characters, including 9 numeric characters. But there is a catch, that accepts white space whatever the position. function validaCampo(sCampo) {…
-
6
votes1
answer181
viewsRegex using preg_replace to separate values according to ")"
I need to use a string separation for the occurrences of closing of parentheses and a space after, with the following technique I managed to do: preg_replace('/[\)][\s]/', '$0--> $1', '1 () 2 ()…
-
6
votes2
answers135
viewsDifference between metacharacters . * and +
Consider this set of strings: my_names <- c('onda', 'ondas', 'ondass', 'ondassssssss', 'ond', 'on') Using the R language, I checked the metacharacters .* and + bring the same information:…
-
6
votes2
answers187
viewsHow does regular expression with double range work?
I am studying regex and had a doubt when dealing with the range operator (-). I understand a creak like [a-z] means "the whole alphabet in lowercase letters" and that a range like [^A-R]it would be…
-
6
votes1
answer259
viewsCreating regular expressions with a dynamic pattern is problematic? If so, is there a way to avoid the problem?
Let’s say, for some reason, I need to create a regular expression that has a part of its standard configurable by a user. Something like this very trivial example: const regex = new RegExp('^' +…
-
6
votes1
answer99
viewsWhat are the differences between String.prototype.match and String.prototype.matchAll methods?
Historically, Javascript relies on the method String.prototype.match to perform, for example, string searches through a pattern via regular expression. However, starting with Ecmascript 2020,…
-
6
votes1
answer83
viewsDisplay conditional text snippet with regex
I am trying to create a dynamic text "generator" that will replace patterns with data from an array using regex, the structure is as follows: Hello, [user], your registration was made in…
-
5
votes3
answers2176
viewsCommand to replace characters recursively
I need a command that overwrites a specific pattern on each line of a file as many times as necessary until the pattern is no longer found. For example, in a CSV file, fields are separated by a…
-
5
votes1
answer550
viewsHow do I validate an email field on Dart?
I created a simple project in Dart whose intention is to validate an e-mail field when a button is clicked, showing an error message. However, the function Regexp.hasMath is always returning false.…
-
5
votes5
answers727
viewsReturn all CSS classes with Regular Expression
I need to return all the classes found within a CSS string, so that when the expression conflicts with: div.classe1{/*...*/} .classe2 div a{/*...*/} .classe3.classe4{/*...*/} .classe5{/*...*/}…
-
5
votes2
answers131
viewsPick singularly characters in a multiple string
Hello, I need help with a regular expression that satisfies some occurrences of a text file. In this case, I need a regular expression that finds occurrences where there are a minimum number of…
-
5
votes2
answers2943
viewsDeprecated Error: Function ereg()
In the script that I installed gave this error: Deprecated: Function ereg() is deprecated in /home/u844214382/public_html/funciones.php on line 98 Deprecated: Code in row 98: if…
-
5
votes2
answers343
viewsRegex in Javascript: grouping
As input by the user I am expecting pairs of numbers separated by commas: // se for um par só 1-2 // se for mais de um par 1-2,3-4,5-6 I expect something like this to come out: [ [1, 2], [3, 4], [5,…
-
5
votes3
answers51028
viewsRegex - Special Character Removal C#
Regex.Replace. is a great solution to remove accentuation. Now I just can’t do the removal of a character type, I have a string that receives the text "1° General Place", string has the character…
-
5
votes1
answer723
viewsFind all instances of a pattern in a text
I need to write a program that identifies a lowercase letter surrounded by three uppercase letters on each side. For example: "AEIoSDE" == "o" I wrote the code as follows: # coding: utf-8 letra =…