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
-
2
votes1
answer60
viewsReturn multiple keys using REGEXP_SUBSTR
I am trying to read occurrences of text records based on an occurrence. By breaking my head I got the following results: For example I want to take the second name, using as a basis the key Empr.:…
-
2
votes1
answer72
viewsHow do greedy, non-greedy quantifiers work?
import re import requests #o req vai ser a requisição á uma página print(re.findall(r'(?<=href=["\'])https?://.+?(?=["\'])',req.text)) The code is to pick up links on a web page. I know he’s…
-
2
votes2
answers62
viewsRemove numbers and special characters from a text, but not within a word
I would like to remove numbers and/or special characters from a text, but not within a word. Example: texto = "ol@ mundo, eu bebo H20 e nao fumo cig@rro !#& 123" The result should be: ol@ mundo,…
-
2
votes1
answer63
viewsRegex Python Remove everything before the first letter in a string
Another question from REGEX that none of the answers I found follows. I have a dataframe that some strings start erroneously with things that are not Letters, for example : t = ['. Subordinam-se ao…
-
2
votes2
answers75
viewsExtract the price of a text and show it formatted
I need to settle this matter: Considering an excerpt from a search page flying: -Best price without scales R$ 1.367 -Best price with scales R$ 994 1 - Including all fees. Write a regular expression…
-
2
votes1
answer63
viewsHow to apply capitalization in paragraph text with specific classes directly in the page body?
Basing myself in that question, I adapted a specific answer for my case, creating an array with the paragraphs of interest, where my intention is to capitalize the text present in these respective…
-
2
votes1
answer64
viewsRegex: how to select whole sentence (no digits) and insert quotation marks
I got this result from a . csv 9 Abraço de tamanduá 9 Abraço fraterno 9 Correr/partir pro abraço (futebol) I am applying several regex so that the end result is an SQL statement like this: INSERT…
-
2
votes2
answers71
viewsHow to extract substring in string array with Javascript using match?
I have to manipulate a data in the following format: ["nome <email desse nome>"], an array with several strings in the same format. I want to extract in another array only the emails, without…
-
2
votes2
answers53
viewsHow can I exchange elements of a string using the values of an object as argument?
I have this code: const operators = { plus : '+', minus : '-', multiplied : '*', divided : '/' } let question = 'What is 4 plus 6?'; let matchs = question.match(/\d|plus|minus|multiplied|divided/g);…
-
2
votes1
answer39
viewspreg_match_all catch tag and attributes
Link appears like this: < programme start="20210129023700 +0000" stop="20210129030100 +0000" channel="Foodnetworkhd.br"> < title lang="pt">Loucos por Churrasco - S3 E12 - Churrasco…
-
2
votes1
answer58
viewsGet date from a string
I am trying to create a regular expression that returns some dates contained in strings. The formats are: dd/MM/yyyy dd-MM-yyyy dd/MM dd-MM Ex: public static void main(String[] args) { final String…
-
2
votes1
answer35
viewsWhat is the best way to get values within multiple tags in multiple HTML files
I have several HTML pages, so: <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html…
-
2
votes1
answer26
viewsFilter two lines of the file at the same time show only the second?
I have the following fictional file: Location: Estado Title: Bahia Location: Estado Title: Pernanbuco Location: Estado Title: Alagoas Location: Cidade Title: Recife Location: Cidade Title: Barretos…
-
2
votes1
answer49
viewsRemove Javascript comments from the script tag of an HTML, ignoring content from other tags (e.g., base 64 images)
I need to ignore the tags img because some images come in Base64 and contain // which are recognized as comments and are removed, breaking all HTML code. function limpa_html($html){ $pattern =…
-
1
votes2
answers1632
viewsRegex to pick numbers between the second and third "/"
Let’s say I have the following string /product/976935/ How would I make a regex to return only the numbers between the second and third bar? The amount of numbers varies so it’s no use just…
-
1
votes3
answers243
viewsRegex for hexadecimal colors
I have a small doubt: I have a regex that captures in 3 groups (2 values per group) of certain color, but this when I have 6 values(excluding the #), I would like to know how to implement to catch 1…
-
1
votes1
answer84
viewsSUBSTRING_INDEX with REGEX
It has as I make a search of the last name of a people but with regular expression? Today I use the SUBSTRING_INDEX to catch the last name, the more I want to take parts of this last name, when I…
-
1
votes1
answer89
viewsString with spaces - Regex Ismatch returns true when it should return false
I have the following Regex (?=.*\d)(?!.*\s)(?=.*[a-zA-Z\s]).{6,12} If I do tests on site that test Regex, it works, in the view Model Annotation to validate works, but when I do in service…
-
1
votes4
answers912
viewsBehavior of the function preg_match() for short names
I set up a function that takes a full name with X names and surnames and returns only the first and last names. If you have a connective (from, from, from, dos, etc.) before the last surname, it…
-
1
votes1
answer534
viewsCheck word variation in a sentence with Regexp
I have a code that checks phrases that the user types and was tried more without much success, make a code using Regexp check that the user typed a particular phrase without or with word variations.…
-
1
votes3
answers5312
viewsHow to add line break using sed?
How to add a line break in a pipe received output, using sed, only for cases that fit the established pattern? I used sed "s/.*oo.*/&\n/" unsuccessfully. The pattern is OK, but the addition of…
-
1
votes1
answer139
viewsRegexp with only one letter
I wanted to make a RegExp more or less like this 0000-x, that was available only the letter X and numbers from 0 to 9. I did a search on the net, I could only do with numbers or that took all…
-
1
votes2
answers269
viewsRegular Expression does not work correctly on webform
I have the following field and validator in ASP.NET Webform <asp:TextBox ID="txt_Senha" runat="server" CssClass="form-control" placeholder="Senha" TextMode="Password"…
-
1
votes0
answers94
viewsValidate namespace definition
PHP variables, if necessary, can be validated with the following Regular Expression: [a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]* But what about the namespaces? I have a certain string, coming from a…
-
1
votes0
answers92
viewsSave data in excel file through Outlook
I created a Rule, that every time an email arrives with a certain text on Subject executes a scrip, which has the function of going through the entire email and storing certain data in an Excel…
-
1
votes1
answer183
viewsMatch fractional number javascript
I have a script and in one of the lines: return $flag.text().match(/[0-9 ]+(?=\%)/i); reads the numbers of a tag p. Ex: <p>Desconto 15%</p> In case he will read the number 15. As far as…
-
1
votes1
answer485
viewsTake value from a Span field with Curl Parser
I have a question and a problem. Good is the following with Curl I login beauty so far everything well.. but I need to get some information inside the html: <span…
-
1
votes1
answer116
viewsWorking with Regular Expression
I would like to know what is the best way to work with regular expression, so that it becomes a code reader: Example: using System.Text.RegularExpression; void LoadRegex(string filter, RichTextBox…
-
1
votes2
answers247
viewsParse HTML regex problem
Well the doubt I have is this, I need to get the following excerpt of HTML right below: HTML: <section class="ovw-summary"> <div class="ovw-summary__balance balance-amounts">…
-
1
votes1
answer132
viewsReplace occurrences arbitrarily in Javascript
I’m using the method replace() in order to highlight certain words in a sentence. The method replaces only the first occurrence of the target word by default. I’d like to know how make arbitrary…
-
1
votes1
answer134
viewsMYSQL - Return occurrences closer to REGEXP
I need to return the number of occurrences closest to REGEXP, see the example below: SELECT * FROM tabela WHERE nome_produto REGEXP 'vestido|longo|manga|curta' The idea is that this query returns me…
-
1
votes2
answers481
viewsSeparate <script> tag by semicolon
I have a variable you can store plain text and the tags <script> and <img>, delimited by (';'). To separate the information, I use the method split(';'). Works well for texts and…
-
1
votes1
answer412
viewsReturn number with Regular Expression
I have a list of articles from Art. 1 to Art. 2.040., but in each article there are other numbers. I would like to make an expression that: 1 - Capture the numbers always after the string "Art. "…
-
1
votes2
answers612
viewsRegex to select only numbers from 1 to 2,000
I’m doing a search to return the article numbers, used: preg_match_all('/\d+/', $novalinhas, $matches); $artigo = (int)implode('',$matches[0]); It is working, however, in some articles it picks more…
-
1
votes1
answer45
viewsCode abstraction with multiple Replaces
I have this code pad: xml = xml.Replace("<html>", ""); xml = xml.Replace("<head>", ""); xml = xml.Replace("</head>", ""); xml = xml.Replace("<body>", "<certidoes>");…
-
1
votes1
answer86
viewsLink being overwritten incorrectly when using preg_replace
I have a regular expression array that I use to replace url’s/hashtags in links using preg_replace: $regs = array('!(\s|^)((https?://|www\.)+[a-z0-9_./?=;&#-]+)!i', '/#(\w+)/'); $subs = array('…
-
1
votes1
answer235
viewsRegex to capture text block
I need to extract blocks of text that are inside #Regions: #region VARIAVEIS GLOBAIS string aux1 = "teste"; string aux2 = "teste2"; ... #endregion The return would be: string aux1 = "teste"; string…
-
1
votes1
answer268
viewsConvert Jsoup doc to string, apply Regex and return a value in String
I’m using an example I found called Androidjsoup to get the source HTML from a certain page, but I’m not getting just the snippet of code I wish is in a certain <script> In short, the…
-
1
votes1
answer47
viewsProblems with Regular Expression
I have the following beginning of Function sql I will use for a recreation system procedures/Function in C# Create Function dbo.JN_FN_DataAtual(@TESTE INT) And created the regular expression…
-
1
votes1
answer29
viewsDifficulty to get information through Regular Expressions
I’m having trouble getting information using preg_match_all. This information is being taken from an HTML code of an intranet page, but from the information I need, I am managing to collect only…
-
1
votes1
answer180
viewsSearching for names inside a text
I have a string where I need to search by name. The text has no pattern. The name list is an array. So far I have managed to do normally, but I have come across a situation where a given name had a…
-
1
votes2
answers151
views -
1
votes1
answer32
viewsProblem with a field in Regex
I have the following expression: (?!.*"); it captures anything that is separated by the character ; except when ta inside a string. Here’s an example: ABC; #captura o último ; 123; #captura o último…
-
1
votes1
answer294
viewsHow to make the Split in some lines except specific?
I want to make a dynamic list that uses the Regex.Split separating each item by the character of a new line, except when you’re in the fields ( ... ) in my lines of code, as follows the example: var…
-
1
votes2
answers238
viewsphp regex to get 2 groups of href link
Hello, how to mount a REGEX to get 2 groups of all href link <a href="/page/page/categoria/page?page=2&publica=1" rel="next">2</a> Where group 1 would be all link…
-
1
votes1
answer85
viewsSave output after applying an replace
Hello, I have the following code below, but I need to apply a replace in the output(FileOutputStream) picked up via http before saving him. public void DownloadFile(String fileURL, String fileName)…
-
1
votes2
answers777
viewsC# Regular expression for string and Guid validation
(1). I would like to validate a string by checking that it only has {[a-z], [A-Z], [0-9], '-'} if(minhaString.ContemApenas({[a-z], [A-Z], [0-9], '-'}) == true) { // Minha string é válida! } (2). I…
-
1
votes2
answers672
viewsRemove substring with regex
I got the string: var str = "Quantidade [12]"; I need to recover the string but remove the space and the [12], IE, I need to return only the value: Amount. In case the string is var str =…
-
1
votes1
answer301
viewsTreat exception when replacing string via Javascript
I created a simple Javascript function to replace any string with a link within an area in my html. Until then I pass some parameters and this function replaces in my html and inserted the links as…
-
1
votes1
answer118
viewsFind the index of an array that matches a regular expression
According to the PHP Handbook, the function preg_grep returns the entries of a array which combine with regular expression. Example $array = [ 'Banana', 'Maçã', 'Café', 'Biscoito', ]; $array_com_B =…