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
-
3
votes1
answer150
viewsMatch a route with "localhost:4200/test-(dynamic parameter)" at Angular 7
Summary of the problem: It is one of those friendly URL’s that will be sent and within the parentheses will come next to the airport of the city, I need the route to be activated when it comes with…
-
3
votes2
answers1288
viewsReplace last occurrence of "a" in a string
How do I replace the last occurrence of a in a string? var myFrase = prompt(" Digite sua frase aqui: "); for (i = 0; i < myFrase.length; i++) { result = myFrase.charAt(i); if (result == "a") {…
-
3
votes2
answers148
viewsSplit into whois using regular expression
I have a replay with whois. I’d like to perform a split taking the values after the <br /> up to the end of the whois line. For example: on the line <br />person: Ana Flavia Miziara, I…
-
3
votes1
answer193
viewsHow to mount a Regex to identify the state of the interfaces
Using the command ip link show in the terminal I get the following text: 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000link/loopback…
-
3
votes2
answers129
viewsLogic to check month with Regex
I’m trying to verify the months that have 31 days with .test() but when the value for the month is 10 (concerning november, which has 30 days - remembering that in Javascript the months are indexed…
-
3
votes3
answers1959
viewsHow to determine which characters can enter the input?
I have a login form and I have to limit the input to receive characters with the following conditions: A capital letter A number A Special Character A minimum of 8 characters Special characters can…
-
3
votes3
answers279
viewsRegular expression to ignore quote separator
I have to read a csv file with delimiter ;. Only it has lines with values """Analize;Distribuição""", only that it creates another column in this ;. How can I read so he won’t accept ; in quotes as…
-
3
votes2
answers91
viewsForeach preg_match_all
I need to mount an array with all the data coming from another array using preg_match_all,I’m using the following code. $results = array(…
-
3
votes3
answers1314
viewsHow to handle different date formats?
I have an application that at a certain time I recover the obtained date from the system, save it in a table in the database (Sqlite) and then recover it. The problem is that in determinator devices…
-
3
votes2
answers65
viewsHow to convert a txt to csv in perl?
Hello, Little Boy. I am new to perl. I need to convert a txt file to csv. Follow the code I’ve managed so far. #!/usr/bin/perl my $filename = "interfaces.txt"; open(fh, $filename) or die "não…
-
3
votes1
answer438
viewsHow to validate a numerical expression with a regular expression?
I need within my application in PHP7 to validate a numerical expression with a regular expression, the case is that I almost succeeded but I ran into a problem. Non-significant zeros within the…
-
3
votes1
answer68
viewsHow do I save the output of a REGEX to a new file
const dirfile = 'BIG_DATA.HTM' const reg = /(\<td .*)/g const fs = require('fs') const myReadStream…
-
3
votes3
answers333
viewsReturn text between keys, without returning the keys themselves
I used the following java regular expression to return strings that are between keys: \\{[^\\}]+?\\} My program worked almost correctly, but it even returns the key. Algorithm: public static void…
-
3
votes0
answers264
viewsRemove HTML tags with regexp in query
I am trying to query Mysql 5.7 using regexp to ignore HTML tags, so far I have the following query: SELECT * FROM question WHERE question.enunciation REGEXP '[^<|</]center[^\>]' = true…
-
3
votes1
answer755
viewsGet path of valid files with regular expression
Context: I am monitoring file deletion and inclusion actions in a folder through Class FileSystemWatcher with the intention of registering a Log of the actions performed in it. Problem: This folder…
-
3
votes2
answers84
viewsConvert string.match() result to string?
How can I convert the return method match() string? For example: var value:string = ">>>> Ola" var result:string = value.match(/\w+/g) The above example gives error in variable result.…
-
3
votes3
answers1422
viewsSearch for words that contain a certain letter
I need to search the library re for when I pass a letter, return the whole word containing the letter. text = "Texto de busca por palavras contendo a letra z, como por exemplo zebra, zoologico. A…
-
3
votes1
answer297
viewsRegular Expression for a binary string that accepts even number of zeros
As stated in the title, follows the DFA that accepts the proposed language: My question is about the regular expression of that DFA which is as follows:(1*01*01*)*. Conforms to regular expression,…
regexasked 5 years ago Pirategull 659 -
3
votes1
answer94
viewsWhat is the "y" flag in regular expressions? What is its function?
Some time ago I discovered that regular expressions can also use the flag y, call for Sticky. I did not understand very well its function. What is its purpose? Is there any relation with another…
-
3
votes2
answers420
viewsRegular expression that recognizes Portuguese words (accented) using Python
Develop the function frequency(), that takes a string as input, calculates the frequency of each word in the string and returns a dictionary that maps words in the string at its frequency. You must…
-
3
votes2
answers679
viewsRegular expression to validate a password with Python
Passwords must contain at least 5 words (word = 1 or more letters), each separated by a hyphen, a space, a dot, a comma or an underscore. Example: a-b-b-c-d-d OR Passwords must be at least 8…
-
3
votes2
answers168
viewsString.split() function with separator containing brackets and asterisk
I have the following code: String teste = "meta[[*]]etapa[[*]]especif[[*]]unid[[*]]qtd[[*]]01/01/2000[[*]]02/02/2000[[**]]"; String[] split = teste.split("[[*]]"); for (String string : split) {…
-
3
votes2
answers609
viewsRegex for full sentence in capital letters
I’m going through the first column of the body of an HTML table and extracting the text from each of the cells using Javascript and testing against a Regex. Regex has the function of identifying…
-
3
votes1
answer313
viewsRegex to capture spaces, except within quotation marks
I would like a regular expression (PHP) to exclude double spaces out of quotes. update tabela set¬ nome='alberto da silva',¬ telefone='1234'¬ ) I want to capture double spaces, enters, tabs out of…
-
3
votes1
answer51
viewsHow would I let this expression of mine beyond the character - (less) be accepted the + (more) as well?
I have an expression on a input, using pattern, that has some rules, among them: Accept uppercase letters, lowercase, minimum of 5 characters, do not accept special characters (only accept the -).…
-
3
votes1
answer131
viewsWhat is the advantage of using Perl-compatible regular expression functions or POSIX-compatible ones in PHP? In what context do you use both?
PHP has regular expression functions compatible with Perl and POSIX. However, I can’t see if one stands out from the other or which contexts of use favor one or the other. It would just be a matter…
-
3
votes1
answer354
viewsRegex in input Pattern is not valid, but the expression is functional
I have a field on a form that can only accept Youtube or Vimeo Urls. Having this, I found the following regex:…
-
3
votes1
answer92
viewsRegular Expression for numbers between certain ranges
I needed to make a regular expression where I only accept the numbers of 11-14, 21-24, 31-34. I made the following regular expression: ^\A[11-14|21-24|31-34]{2}$ It is working, but why are you also…
-
3
votes2
answers277
viewsHow to capture a number in a string using regular expressions (or similar method) in Python?
I would like to know how I can select a specific part of my text considering that this part refers to a value that can change. For example, the string: # 44,739 % of all cache refs I would like to…
-
3
votes1
answer234
viewsValidate input by accepting specific amount of letters and numbers in javascript "for an RA, ex: p3087748"
I did a validation in HTML using pattern, I tried to put letters and numbers at the same time. But I believe that there is no way to determine the minimum of letter and numbers. Example: Only one…
-
3
votes2
answers293
viewsReplace string chunk between 2 indexes
I have a long string inside a txt file, for example, let’s say my string is about that: strg = '123456 BANANA 00 SP' In position 14 and 15 we have the "00", I’m gonna need to replace up front The…
-
3
votes1
answer42
viewsStandardize phone number with REGEX on R
library(tidyverse) I’m trying to standardize the "numero_telefonico" column of this dataset: https://raw.githubusercontent.com/rivaquiroga/latinr-taller-regex/master/datos/telefonos.csv Download the…
-
3
votes1
answer39
viewsregex python delete all after the second occurrence of a whitespace
That should be very simple and I can’t find an answer. I have several strings of different sizes that have more or less the same pattern: 'Art. 1° E' 'Art. 15. As' What I want to do is delete…
-
3
votes1
answer103
viewsWhat is the Unicode flag "u" in regular expressions? What is its function?
Some time ago I discovered that regular expressions can also use the flag u, which I think is short for Unicode. What is the purpose of this flag? I know it was added in some recent version of…
-
3
votes1
answer142
viewsRegex is not checking the accented character, even though it is in the expression
I have the following Python regex to filter my application text input: import re good_chars_regexp = re.compile(r"^[A-Za-záéíóúÁÉÍÓÚâêîôÂÊÎÔãõÃÕçÇ00-9\,\.\-\?\"\'\’\!\“\s\;\:\“\”\–\‘\’\’\/\\]+$",…
-
3
votes2
answers413
viewsHow to copy files from one directory to another using regex?
On the linux terminal, when I want to list files in a directory using regex, I do: #exemplo listando arquivos começando com uma letra maiúscula ls | grep -oP '^[A-Z].+' The flag oP is used for…
-
3
votes2
answers311
viewsHow to use re.split() to pick only the words of a text, ignoring numbers and punctuation marks
I am given the following sentence:: texto = """ Em 2020 observamos, e catalogamos (com fotografias), os barcos que chegaram ao Porto! Até breve. """ for p in gerarPalavras(texto): print(p) I created…
-
3
votes2
answers50
viewsHow to avoid Greedy Repetition (.*) to search for string that has defined start, dynamic middle and defined end?
I have a log file that is searched via regex ^WebServer:.*endOfLine. Considering the log below this regex is generating 485 iterations (Steps): String: amet, consectetur adipiscing elit...Lorem…
regexasked 3 years, 11 months ago Fábio Jânio 3,407 -
3
votes1
answer60
viewsFind content between 2 strings inside a giant string with Regexp
I need to create a function that takes the frame number and takes its contents from a file . txt with more than 3000 lines. Every table has the following configuration: Starts with "Frame X" and…
-
3
votes1
answer72
viewsRegex how to separate by groups each occurrence
I’m trying to add attributes to a tag tag <a> from a parse of Markdown (markdown => html). In my document markdown i add parentheses and the markup I want right after declaring the links,…
-
3
votes3
answers68
viewsRegular expression to take one or more occurrences that precede and follow a given letter
I have the following cases... a first text as follows:: let text = "olá meu numero é trezentos e vinte e quatro tudo bem?" And this text I want to receive can also be as an example: let text = "olá…
-
3
votes2
answers87
viewsRegex to catch single word
I’m trying to create a regex that takes an exact value within a text, example: let texto = "troquei meu carro por um outro carro uma carroça" console.log(texto.replace(/carro/g, 'barco')) The…
-
3
votes2
answers84
viewsHow to access the position of multiple matchs of a regex in a string?
I know I can access the position of a match of a regex in a string using the methods start, end and span. Example of a program that identifies repetitions in a text: import re from colorama import…
-
2
votes5
answers6608
viewsCapture dates of a text using regular expression in javascript
I have a function that returns data in JSON and places in certain places with jQuery. One of these data is a text that contains a period of dates (Beginning and end). Example of returned text:…
-
2
votes1
answer234
viewsRegular expression for picking up HTTP input and header
How to construct a regular expression that selects this here? Set-Cookie: csrftoken=bf8748c0b1e113430d9757cf0ed06f4a; expires=Mon, 04-May-2015 20:54:08 GMT; Max-Age=31449600; Path=/ <input…
-
2
votes2
answers2139
views -
2
votes1
answer376
views -
2
votes3
answers210
viewsHTML tags with Regex
Here’s the thing, I’m using the following expression: <div class="teste">(.+?)</div> And that’s the content, for example.: <div…
-
2
votes6
answers261
viewsParser Bbcode ignore what is inside [code]
I made a bbcode parser based on some to meet my needs, but I have some problems. The code inside [code] should be ignored, but I don’t know how I could do it, since it has all the other tags that…
-
2
votes3
answers10545
viewsRegular Expression White Space
With the following regular expression (^DOC)*[0-9] I can capture all numbers after the "DOC" sequence. However, by testing this text : TEXT TEXT TEXT DOCUMENT:240010 24/09/2014 It returns me…