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
answer573
viewsRegular PHP expression, how to remove open html tags?
Hi! I need to remove an html chunk that bugged my string, it looks like this: e="text-align:left;"> Texto normal ... This generates a visual error. Another error generating is at the end of the…
-
2
votes1
answer398
viewsmysqli_query returns false to select done with REGEXP
I am having the following problem: I am trying to capture a table row of my database using a regex and, when entering the code in the Mysql terminal, it captures the line normally. Already in my php…
-
2
votes1
answer838
viewsHow to validate Date with Regex?
I am trying to capture a date inside a string using regex, but when I try to recover the part of the string returns me the following error: analyzing " TARIFF:([ d/]+)" - Unrecognised exhaust…
-
2
votes1
answer194
viewsValidate increasing and decreasing numbers with regex
I need to create a regex for increasing and decreasing number validation as an example: Repeated | increasing | Decreasing 000000 | 012345 | 987654 111111 | 123456 | 543210 [09:30:16] William…
-
2
votes2
answers536
viewsHow to remove a part of the string at the beginning or after the space?
I need to exchange names started with HE for E as for example HELIANE HELIAS for ELIANE ELIAS but it may be WILLIAM HENRY and switch to GUILHERME ENRIQUE…
-
2
votes1
answer81
viewsDelete symbol from the last position of a string, optimally with PHP
I would like to delete the last character of a string if it is a symbol. I know I could do it in a complex way like the following function: $string = "minha_string_com_simbolo_no_final_"; function…
-
2
votes3
answers112
viewsswap Z for S char between vowels in a string
How can I exchange all occurrences of the letter Z between S within a string for example TEREZA , CEZAR, BRAZIL, HOOK would be TERESA , CESAR, BRASIL, ANZOL…
-
2
votes1
answer148
viewsIs it possible to bypass (bypass) a regular expression?
I am reading a little about regex for some validations and I wanted to know if there is any way to circumvent some rule, for example: $rule = "/[^A-Za-z0-9]/"; I found this to validate alphanumeric…
-
2
votes2
answers1231
viewsRegular expression (regex) for links to web pages using Python
I am trying to learn how to create a webcrawler. Part of the code will be to extract links on a web page (links starting with http or https): import re urls = re.findall(r'href=[\'"]?([^\'"…
-
2
votes2
answers3961
viewsHow to do a preg_replace with various conditions and changes?
How to make a PREG_REPLACE having several search and several substitutions at the same time For example I want ('/(BR|BL)/', 'B') if you have BR and BL replace with B and also ('/PH/', 'F') if PH is…
-
2
votes1
answer333
viewsRegular expression to identify text box in HTML form
Situation Give up a page in any HTML where there is a form containing, at first, two text boxes, one for name and the other for email. Then came the need, to do some tests on Android, to get just a…
-
2
votes3
answers1209
viewsExtract numbers from a list using Regex
I have the following list <type 'list'>: [u'1',u'2'',u'3',u'4',u'7'] The result I hope is: 1 2 3 4 7 I tried to use the re.findall(r'\d+', variavel) But it doesn’t work, note that I also need…
-
2
votes2
answers236
viewsRegex for different system subdomains or domain
I am developing a system where each user will have their subdomain according to their login but I will also allow them to configure their own domain. As I am developing locally, I have also added…
-
2
votes1
answer68
viewsPreg_match_all, get input name attribute values
I am doing a project with dynamic forms, that is, the user (administrator) can make his own form (HTML/CSS), but when fetching the form from the database I need to check if the names (name) of…
-
2
votes1
answer320
viewsHow to create a user friendly URL with undefined number of parameters
Hello, would anyone know how to do this regular expression in . htaccess? I need to make the URL pattern friendly in this format: http://dominio.com.br/usuario/joao.json…
-
2
votes3
answers331
viewsPHP remove a URI snippet with regular expression
I have the following Uri $uri = "http://www.meudominio.com.br/pagina.php?campo=teste&ordem=2&cor=azul" how to remove the "ordem=2" of the above url with regular expression, knowing that the…
-
2
votes1
answer107
viewsApache mod_rewrite
I have a rewrite rule I found in a very old question of the US: RewriteCond %{QUERY_STRING} ^(.*)$ RewriteRule ^(.*/)([^/]+)/([^/]+) $1?$2=$3&%1 [L] RewriteCond %{QUERY_STRING} ^(.*)$…
-
2
votes1
answer140
viewsSet a group in regex
I’m testing the following regex: (?i)(\s|\W|)(fire|fire-type)(\s|\W) I have 2 problems: 1º Case (SOLVED) has only one word without spaces at the beginning or at the end my regex does not take. Ex:…
-
2
votes2
answers354
viewsValidate preg_replace domain
My question is this, I have the following function: $site = preg_replace("/[^a-zA-Z0-9]/", "", $_POST['site']); But when using in the string www.lostscavenge.com.br, that regular expression emits…
-
2
votes3
answers522
viewsRegular expression, PHP
What is the correct way to validate the string for the nomenclature below, using Regular expression? /filmes/todos-filmes/notas-espectadores/?page=[SÓ NUMEROS]
-
2
votes1
answer31
viewsProblem capturing string type with Altorouter router
I’m using Altorouter to make the page call of my project, and in his doc says that to use "Match Types" custom just add $router->addMatchTypes(array('cId' => '[a-zA-Z]{2}[0-9](?:_[0-9]++)?'));…
-
2
votes1
answer3803
viewsHow to indicate in a regex that the symbols '(' and ')', the parentheses, are one of the alternatives in a list of symbols in Java?
I am developing a code that captures a text using regular expressions (regex). This text consists of parentheses. The point is that parentheses are used in regular expressions as a group definator…
-
2
votes3
answers5128
viewsHow to allow only numbers and dashes with preg_replace?
I have a question regarding preg_replace, would like to know how could you do to allow only numbers, and hyphens (-). My code is this:: $ola = preg_replace('/[^[:alnum:]_]/', '',$_POST['ola']); How…
-
2
votes2
answers110
viewsTreat all hexadecimal colors in a.css file using php and regex
I don’t know if you can help me but I want to replace the color in the "#xxxxxx" format in a CSS via Regular expression and PHP. I have a function that calculates the color and replaces it with the…
-
2
votes6
answers615
viewsRegular Expressions with Java Patterns
I need to do a college exercise, which is this: Validate with regular expressions any word that contains exactly two characters 'a' and two characters 'b' or more. I made the following expression in…
-
2
votes1
answer212
viewsStrsplit regular expression
How to assign E.R. to separate the city name ? cid <- c(cidade1..SP.Brasil,cidade2...SP.Brasil,cidade3..SPDF.Brasil,cidade4...SPDF.Brasil) In the sublime for example, this works:…
-
2
votes2
answers522
viewsInsert string in first column
I am breaking my head with something very simple, I need to insert a ";" (point and comma) after a Sort/Uniq in a file. As it returns the number of repeated lines, I need this return that is always…
-
2
votes2
answers404
viewsExtract groups with regex
I need to extract the Session and the date from the line below, and the date I have separated with dash and slash. The Patterns work properly individually but when I try to extract both, nothing…
-
2
votes2
answers220
viewsRegex: Open and close with the same character and allow more than one type
It is possible to get a text between two characters that are equal, with the following conditions: The opening character shall be the same as the closing character. Allow more than one character…
-
2
votes1
answer69
viewsRegex to involve console.log expression in eclipse find/replace
I’m trying to involve everyone console.log(); of my code with the condicional if(showLog) { }. I was learning regex and found I could select all the expressions console.log() including those…
-
2
votes2
answers1898
viewsRegex to pick up text between <> in python?
I would like to extract the text contained between <> of a string. At first, I built the following expression: import re m=re.search(r'<(.*)>','abevbv envvrhwkv <eiwbv> ebvi…
-
2
votes2
answers77
viewsHow to modify specific parts within an html file?
I am loading an html file and would like to modify urls within it so that the system recognizes the actual path of each file that html is trying to access, so I have several different urls: <link…
-
2
votes1
answer504
viewsI need to select sequences of numbers in a field of a table column
I have a 'Text' column in my 'process' table. Text consists of a VARCHAR (220), in this text I need to identify a specific word pattern. In this case a sequence of numbers with a "-" to separate:…
-
2
votes2
answers107
viewsGet content that is before the number using regex
$MinhaString = "Aventura, Fantasia, Ação 25 de maio a 31 de maio" I tried to do it this way, only it doesn’t work. $Genero = strstr ($MinhaString,"/[^0-9]/",true); I only need "Adventure, Fantasy,…
-
2
votes1
answer90
viewsInsert 0 when you have 10 numbers
I have the following sequence: 3531399402 It has 10 numbers, with this regex I can list these occurrences: ^\d{10}$ I am using a text editor and I need to replace these occurrences and insert a 0…
-
2
votes1
answer89
viewsregex to replace the $_POST['field'] string with $this->input->post('field') from codeigniter
I’m trying to find a way to replace the sequence $_POST['INPUT'] for $this->input->post('INPUT') of codeigniter, in my editor phpstorm, using the replace with the option regex active. So,…
-
2
votes2
answers348
viewsMatch in regular expression with special REGEX symbols and line breaks
I need help with a regular expression match in a string whose: beginning and end of a line with the character } keep marrying everything you find in the next line (including other "escaped"…
-
2
votes1
answer190
viewsMake different combinations of words within a sentence
As an example I have the following sentence: texto = O gato subiu no telhado de 10m, um homem jogou-lhe uma pedra e ele caiu de uma altura de 20m. I want to extract the following information: (O…
-
2
votes2
answers204
viewscheck jquery email as if it were two strings
Good evening, I’m finalizing a form check and I’ve locked on at one point, maybe by the way they wrote the code of my work I can’t use jquery validate, then I have trouble checking a field of input…
-
2
votes2
answers200
viewsError validating with Regex
I am trying to format this text with regex but do not have the desired return: Of: "ST STN, SET J, ? SHOPS T-40 /T41, - TER-REO, SHOPPING & BOULEVARD KM 28.5 VALUE 450.00 CENTRAL." To: "ST STN…
-
2
votes2
answers116
viewsFind attribute value with regex
I get a string for an RSS feed, the part that matters is the following: &lt;table feedtag="divinegoblin" ... Each piece of the feed will always have this attribute feedtag="...". I would…
regexasked 7 years, 5 months ago Artur Trapp 5,175 -
2
votes1
answer139
viewsRegex to capture fixed strings in HTML and JS codes
I’m doing some automated testing for a project legacy in the MVC model, however, there is a requirement for one of them to capture all fixed strings in HTML and JS codes. Since the project company…
-
2
votes3
answers1468
viewsFirst and last character occurrence
In Javascript, how to extract from a string everything that is between the first occurrence of [ and the last occurrence of ] ? Ex: <HR>\n[{"key":"value","key2":["¥"]}]\n<HR>…
-
2
votes3
answers199
viewsHow to make a look-Behind using quantifiers such as the " d+"?
I need to match the "test" text, but the string will not always start with a fixed number of characters/digits, it may start with any number of characters, example: 001 test 0002 test 20458 test How…
regexasked 7 years, 6 months ago Thiago Hencke 113 -
2
votes2
answers1104
viewsValidate inputs in form with regular expressions
I have Contacts field on the page where the user must fill, for example, the name, it should only type letters, in the phone field, only numbers and email required the use of "@". The idea is to…
-
2
votes2
answers1013
viewsRegular expression to select whole word and case sensitive in sharp word
I need to make a program that searches a certain word in a set of texts and marks the word searched in the middle of the text. For this I developed the following method: public void…
-
2
votes5
answers4863
viewsHow to make a regex that ignores non-alphanumeric characters?
For example: a regex that finds a match in the string "currency" but also finds a match in the string (m, .o, e.d...a). That is, it ignores non-alphanumeric characters regardless of position or…
regexasked 7 years, 2 months ago Felipe Padilha 21 -
2
votes2
answers98
viewsHow to remove the Comma from the last occurrence [PERL]
Well I have a perl script that formats a json leaving it in this format: {"nome1":"123","nome2":"123","nome3":"123",} but I want only in the last instance to remain only the key without the comma…
-
2
votes1
answer1978
viewsJava regular expression (validating password)
I need a regular expression to validate the following password: The password must contain at least one element of each: More than 6 characters; Upper and lower case letters; Numbers; Special…
-
2
votes2
answers422
viewsCapture words using Regular Expressions
I have the following text example: Meusreportspdf001-Capa-Disclaimer-22012017 I want to capture with php regular expressions the texts "Cover", "Disclaimer" and "22012017". I’m trying to use the…