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
-
4
votes1
answer104
viewsProblems with PHP regular expressions?
I’m getting a file .txt and excluding the letters and lines in white. It is giving problem with the special character \t or \s he doesn’t recognize. The code below: <?php function pass1() {…
-
4
votes3
answers2168
viewsValidate name field - Jquery
I would like to know how to validate a name field, to accept: Letters (Upper and Lower Case) Numbers Spaces Maximum 30 characters There can be no double space There cannot be space at the beginning…
-
4
votes3
answers749
viewsHow to treat High and Low Letters Box along with Symbols
I got the following snippet spinning pretty: function busca() { var str = document.getElementById('txt').value; if(document.getElementById(str)) console.log(str + ' existe.'); else console.log(str +…
-
4
votes5
answers3695
viewsRegular expression to find bar
I need to validate a field and it must have the following format: two letters/numbers. Ex.: RN/1234567. The two letters will always be uppercase and the number quantity has no limit.
-
4
votes3
answers2636
views"Find and replace" with regular expressions in MS Word 2016
I have a list with the result of candidates for an open competition I want to sort by note. However, before making the ranking need to remove the registration number of each competitor, which…
-
4
votes2
answers246
viewsAWK regular expression print inside brackets
look, inside my.txt file has the following description: Flags: X - disabled, E - established 0 E name="peer1_cymru" instance=default remote-address=38.xx.xx.xx remote-as=65555 tcp-md5-key="WUf4f8"…
-
4
votes1
answer101
viewsRegex custom python time 3
I need to create a regex that accepts the following entries: 8:00 8 horas 8h 8h30 (8h 30) 8h30min (8h 30 min) 8h30minutos (8h 30 minutos) and I arrived at the following: ((\d{1,2}:\d{1,2}) |…
-
4
votes2
answers151
viewsFilter filenames in uppercase and with a particular snippet at the end
I have some files named with person names, but some are completely uppercase, others completely lowercase and some even mixed case. I would like to set up a regex to, from a list, filter only the…
regexasked 7 years, 6 months ago user28595 -
4
votes1
answer164
viewsRegular expressions, difference between [-] and -
I am working with some regular expressions and I came across the following case: string pattern = @"^.{2,9}[-].{4}[-].{4}$"; string pattern = @"^.{2,9}-.{4}-.{4}$"; I would like to understand, what…
regexasked 7 years, 1 month ago Thomas Erich Pimentel 3,059 -
4
votes1
answer47
viewsREGEX of HH:MM:SS may be negative
I’m working with HH:MM:SS and I have this REGEX ^([0-1]?\\d{0,4})(?::([0-5]?\\d))?(?::([0-5]?\\d))?$ I’m using the library Inputmask but I would like to work with negative hours example: Effort:…
regexasked 7 years ago Fernando Souza 1,887 -
4
votes1
answer2281
viewsRegex no Delphi
A help with regular expressions in Delphi 10 please. I need to check the following on a string: Size ranging from a minimum of 6 characters to a maximum of 20 characters; Character type: a-z or A-Z…
-
4
votes2
answers1556
viewsRegular expression 6 decimal places
Can anyone tell me if it is possible to create a regular expression with the following characteristics: value between 31.000000 and 43.000000 the value may have 6 decimal places, but must be in the…
regexasked 6 years, 11 months ago Joana Nóbrega 51 -
4
votes2
answers793
viewsChatbot in Python with NLTK
I am beginner in python, for some time I have been interested in Text Mining and I would like to ask for a help with a doubt in a project. For some time I have been studying how to use the Python…
-
4
votes2
answers134
viewsREGEX - Small details that don’t match
I have that expression: (?:[ \t]*[a-z][)]\s*)?([^\r\n<]+(?:(?:\r?\n(?!\s*[a-z][)])|<(?!br\s*\/?>(?:\s*<br\s*\/?>)*\s*(?:\s+[a-z][)]|\s*$)))[^\r\n<]*)*)(?:<br\s*\/?>\s*)*…
-
4
votes1
answer181
viewsHow to replace each occurrence of a regular expression match with a different value?
I have a text (html code) with several images in standard HTML format: <img src="X" atributos /> I need the value of the attribute src is replaced by the identifier CID:# where # is a unique…
-
4
votes2
answers58
viewsHow can I create a regular expression that accepts a certain number at most once
I am learning to use Regex and I would like to know if I can make it accept at most a number 2 in some sequence (can contain letters or numbers) Ex. "sskfdam09471928" Approved "asldk02210920139"…
-
4
votes5
answers286
viewsRegex to capture dimensions of a product with unit of measure
I have a python function to capture the dimensions of a product in Lxcxa format but I can’t make it work for cases where the unit of measure between the values appears, regex is this one: def…
-
4
votes3
answers681
viewsExtract date with Regex
I’m trying to extract a date from a string, but I’m not getting it. Example: String stringQualquer = "um teste qualquer12/02/1998 19/09/1880 Nulo"; I want to pick up the first date of this example…
-
4
votes1
answer7418
viewsHow to insert white spaces - Javascript
I am doing some exercises and one of them asks me to create a code that reproduces an "ASCII art", I read about and saw that it was a special character and I tried to insert the space in its Unicode…
-
4
votes1
answer618
viewsRegular expression does not validate password when I type only numbers
I am using this regular expression to validate my password, the password must have only letters and numbers, must have at least a letter and a number. (Minimum 8 characters). I’m using that…
-
4
votes1
answer1269
viewsRegex for repeat numbers on CNPJ
I have the following regular expression: regex:/^\d{2}\.\d{3}\.\d{3}\/\d{4}\\-\d{2}$/ I can validate for that, but not for repeated numbers. I want to apply within this regex, a form that does not…
-
4
votes1
answer593
viewscapture Pattern groups with regex
How do I capture group-separated information with regex? I have a string with the following format: /+1-541-754-3010 156 Alphand_St. <J Steeve> 133, Green, Rd. <E Kustur> NY-56423…
-
4
votes3
answers2117
viewsRegular expression to return text between keys
I have this String: str = "Eu sou uma string {dentro de uma string {dentro de outra} }" What regular expression can I use to get just: dentro de uma string {dentro de outra}…
-
4
votes2
answers396
viewsUsing REGEX in PHP to capture any number that is not within single quotes
I have been studying regex for some time and now I have a problem: capture all the numbers, including decimals, other than in single quotes. I’m creating a kind of Viewer for PHP code in order to…
-
4
votes2
answers1799
viewsOperator "AND" in Regex
I’m trying to use the operator AND in regex. I have looked at that link, but this case did not help me. My case is, for example, in the text: "FORT/310117/200826/12979898000170" I want you to return…
-
4
votes3
answers1422
viewsClear string with Regex
I have the following array in PHP: [ "Opcao 01 - Frase aleatória - Menu Superior", "Opcao 02 - Outra Frase aleatória - Menu Su", "Opcao 03 - Mais 01 Frase - Menu", "Opcao 04 - Mais Frase -", "Opcao…
-
4
votes1
answer1154
viewsHow to remove text from a string in a data frame column in r?
Hello! I have the following dataframe: Município (Código) Município Valor 2 1100015 Alta Floresta D'Oeste - RO 408765 3 1100023 Ariquemes - RO 477322 4 1100031 Cabixi - RO 126630 5 1100049 Cacoal -…
-
4
votes2
answers65
viewsHow to identify acronyms with Regex Javascript
I need to identify acronyms that: Start with P Has 3 characters The last 2 characters can be digits or letters. Currently, I managed to create the regex \b(?:[A-Za-z0-9]){3} but unfortunately I’m…
-
4
votes2
answers122
viewsHow to create regular expression to search for numbers in parentheses?
I’m trying to create a Regex to get numbers that are in parentheses. So: 1) Pergunta 1 2) Pergunta 2 3) Pergunta 3 4) Pergunta 4 . . 10) Pergunta 10 So far I’ve managed to reach that: (^[0-9].* )…
regexasked 5 years, 8 months ago Diego Souza 16,524 -
4
votes1
answer247
viewsUsing replace in a character in the middle of a String to add text before and after the String
I have this expression stored in a String: 1 * Math.pow(x, 3.0) + 4 * Math.pow(x, 2.0) + 1 * Math.pow(x, 1.0) + 27 However, I use a derivation library that only accepts the character ^ to make…
-
4
votes2
answers187
viewsHow to remove characters q, ç and g from the HTML <u> tag in Regex?
I am converting HTML to doc, and I came across a very specific problem. Words that contain the letters q, g and ç when underlined, are getting an unwanted result. I thought I’d settle this way:…
-
4
votes1
answer63
viewsWhat is the "groups" property in the result of a Regex?
When searching for a certain occurrence in a string with Regex without the flag g (of global), the result comes, in addition to the array with the occurrence found, other properties such as index,…
-
4
votes2
answers2472
viewsFetch words between quotation marks through regular expression
The code below is returning me this error: Notice: Undefined offset: 1 Code: <?php $matches = array(); # Executa expressao $string1 = 'string(10) "CURITIBA" string(11) "SP"'; $pattern =…
-
4
votes2
answers95
viewsRemove specific set from the end of the regex array
GOAL I am trying to remove all elements of the array from the contents ":PM" with regex, but is returning me error. DETAILS The array will always contain ":PM", and it is only this part that I wish…
-
4
votes2
answers89
viewsRearview Metacharacter x does not take the corresponding groups when I change the order of these
The rear-view metacharacter \x repeats something captured in some group () previous in regex. For example: library(stringr) a <- 'quero-quero' str_extract(string = a, pattern = regex(pattern =…
-
4
votes4
answers200
viewsFind character succeeded by another character using Regex
I am trying to assemble a regular expression that can identify and correct an invalid JSON. What I am trying to do specifically is the following, using as an example the following JSON: { "array":…
-
4
votes1
answer665
viewsHow does the metacharacter t work in a regex?
I have this variable: y <- c('stack overflow', 'user number 2', 'nova\nlinha', 'nova \n linha') And these functions with their results: library(tidyverse) With \n: str_detect(string = y,…
-
4
votes1
answer183
viewsDifference between the metacharacters b and B
The metacharacters \b and \B sane anchors that marks the boundaries of a string (where it starts, ends, or both). Works by the ASCII standard, containing only [A-Za-z0-9_]. That is, only parts of…
-
4
votes1
answer237
viewsRegex for positive, negative, sum and subtraction number tokens
I have to do a lexical parser in python using the PLY. Use REGEX to pick up tokens: Example: t_FLUTUANTE = r'flutuante' The expression above gives a match with the word flutuante and return me a…
-
4
votes2
answers112
viewsfunction does not execute regex equal words
I got some string: "novamente mais brevemente uma vez claro, claramente demente, igualmente. novamente." I run a Javascript regex to get the words finished in "mind": var target =…
-
4
votes1
answer137
viewsHow to create a regex equivalent to a BNF?
I need to create a regular expression that is equivalent to the following BNF: <SEQ> ::= <DIG><SEQ> | <DIG> <DIG> ::= 0|1 I tried to create a Python code with the regex…
-
4
votes1
answer44
viewsValidate from 1 to 6 digits, the first of which cannot be zero
How is regex to validate the following rule: Numbers only; A maximum of 6 numbers, and a minimum of 1; The first number needs to be different from 0; I tried it this way and it didn’t work:…
regexasked 3 years, 12 months ago V. Rodrigues 75 -
4
votes1
answer63
viewsFunction to find complete word, but independent of position in string
I’m having trouble using the str_detect to capture part of a text. I need the str_detect take only the word "garlic", but regardless of her position in the string. Ex: "Brazilian garlic", "Brazilian…
-
3
votes4
answers5635
viewsMake a regex to remove characters
In a return of a jquery function, the date returned comes in this format. /Date(1401731794773)/ I would like to remove the invalid characters on that date, which are: /Date( and )/ I only need the…
-
3
votes3
answers43625
viewsRegular expression that accepts only numbers and/or letters in Java
How to develop a regular expression that allows a string to have only numbers and/or letters in any position and quantities? Examples: to) 00000a b) 000000000A c) AAAAAAAAA0 d) 1AAAAA1113 and)…
-
3
votes2
answers25883
viewsHow to remove backslashes ( ) and quotes (") from a string?
I would like to prevent the use of these characters in a string. I think the most elegant way would be by regular expression, but I don’t understand anything about putting together a. A replace…
-
3
votes2
answers125
viewsHow to loop with regex in javascript?
Hello everybody all right? I’m cracking my head on the following question: I have a string set: var teste = blabla 555.. 999 I have double white space between the digits and did the regex: var str =…
-
3
votes3
answers226
viewsPicking Indentation with Regular Expression
I would like someone to help me create an ER that takes only one tag and all lines that are indented in front. example: aaa abab aca marcacao aaa abab aca cc cc bb With the above code the ER would…
-
3
votes1
answer400
viewsRegular expression to extract numbers from "200#5;300#10"
What would be the best regular expression for the following entry "200#5;300#10" ?
-
3
votes2
answers243
viewsRegex between words
I’m trying to make an appointment Regex return to me in a source code file statements that are not public %%Enum Tipo, but I’m not very familiar with Regex and I’m having a little trouble, someone…