Most voted "preg-match" questions
PHP function for string matches using Regular Expressions (Regex). Use this tag when the doubt is related to the use of the function and its parameters.
Learn more…53 questions
Sort by count of
-
7
votes1
answer128
viewsIs there any way to optimize this code?
How to optimize this code to make it faster? if (strpos($qt, "blood") !== FALSE){ if (preg_match("/^blood (?<blood>.+)$/", $qt, $match)){ switch ($match['blood']) { case "a+": $result = "A+";…
-
5
votes3
answers2397
viewsHow to check if there is a certain number in a php variable?
So I was doing a search, looking for some php function that checks if a certain number exists within a variable. And I found the preg_match(). Only that has a however, php gives an error and so I…
-
5
votes2
answers3202
viewsRegular expression for repeated characters
Does anyone know if it is possible to check if a string has all the same characters? For example, can characters followed or more than one in the same string, but not all the same: That may: $str =…
-
4
votes2
answers480
viewsSingle vs. Double Quotes in PHP Regex
whereas I own a path which I wish to verify with preg_match if it is the desired path, what is the difference between the two operations to follow? // Single quoted string…
-
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
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 =…
-
3
votes2
answers987
viewsPHP: Picking up function argument with preg_match_all
Good afternoon: I’m picking up to pick up the value of calls to a certain PHP function straight from the source code. What I need to do is sweep each of the lines of the source code, and if there is…
-
3
votes2
answers535
viewspreg_match(...) for various text types
How can I validate the texts below? Letters (including accents) and numbers (without spacing), separated by . or . e.g. 'olá123' Integers and/or decimals. ex: '22' or '2.2'
-
3
votes1
answer247
viewsI can’t do a word search between brackets in php
I created a function to check if some words exist in an array. I want to search for words within "[ ] brackets". Example: [how] [to give], [to love] ... For this, I am using the function…
-
3
votes1
answer118
viewsHow to create a function that validates if there is a Mysql function in a given string?
I am looking for a function that identifies (return true) if there is a Mysql function in a string. These would be some examples of possibility of input to function. <?php $randomstrings = […
-
3
votes1
answer39
viewsSimulate _GET php in string
I have a simulate string to: <li><a title="string" href="http://geting.com/?v=123?t=abc">Opção 1</a></li> I’d like something to take the parameter ?v=, just him, just like…
-
2
votes1
answer120
viewsWhen fetching the attribute of a tag, it is bringing the value of another
function returnvalue($namearr,$exec){ $result=""; foreach($namearr as $arr => $value) { $regex = '<.* name="'. $value .'".*>'; if (preg_match($regex,$exec,$result1) === false) { $result4="…
-
2
votes1
answer180
viewsWarning when using preg_match()
I had to migrate from PHP 5.2 to 5.3, so thousands of DEPRECATED messages started coming on my PHP system, but some are too complicated, follow the code : if (!preg_match($SUBMENU.':', $sm)) { $sm =…
-
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
answer297
viewsUse of the preg_match
With this code I can block special characters in my input, but I still want him to accept ., - and _ how to proceed? elseif (!preg_match('/^[a-z A-Z0-9]+$/', $username)) { echo json_encode(array(…
-
2
votes1
answer118
viewsAppropriate PREG MATCH rule
I created a loop that shows all months of the year with the following code: for($i = 1;$i <= 12;$i++){ } then I created a $_GET variable that would receive a rule like the following:…
-
2
votes1
answer121
viewsRegex to get comments from a CSS
I have this CSS: :root{ --bodyBackgroundColor: #ffffff; // pegar o comentário não importando o tamanho --bodyTextColor: #ffffff; // outro --buttonBorderFocus: #1d2124; // testando } Response…
-
2
votes1
answer531
viewsGrab only some attributes of HTML tags
I have several inputs, from a curl, but I just need the name and of value of these inputs: <input type="hidden" autocomplete="off" name="timezone" value="180" id="u_0_9"> I have this code:…
-
2
votes3
answers67
viewsRegex is not working with file_get_contents
I have a problem about regex and I come here to ask you for help. I’m trying to get a file value .chr by regex, but it does not return any match, I find it strange because I have tested in regex…
-
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
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…
-
1
votes1
answer243
viewsError with Php and Preg_match
I have the following line in a php file if(preg_match("!\oa!", $id)){ until a couple of months ago this worked normally but began to give this error Warning: preg_match() [Function.preg-match]:…
-
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
votes2
answers156
viewsHow to use preg_match_all in this excerpt?
<div> <span class="dark_text">Type:</span> <a href="https://myanimelist.net/topanime.php?type=var1">var2</a></div>~ I need to use preg_match_all to find the…
-
1
votes1
answer221
viewspreg_match regular expression to pick text between tag
What would be the expression of the preg_match to get the text "exit" within the following tag? <a href="/logout" role="menuitem"> <i class="icon-key"></i> Sair </a>…
preg-matchasked 7 years, 5 months ago Bruno Lazarine 147 -
1
votes2
answers172
viewsproblem with data validation preg_match
hello, good night to everyone I am with a problem in the question of form validation where my preg_match works perfectly however not allow spaces anyone knows tell me how to let the user insert…
-
1
votes1
answer151
viewsPHP: How to use preg_match_all in this excerpt?
Site I want to get the data I need to use preg_match_all to get what’s inside <table class="grid-table survey-info" cellspacing="0"> So far I’ve done the following <?php $url =…
-
1
votes2
answers1541
viewsRegex filter only values in real
I have the following regex: preg_match_all('/([0-9]+[\.]*[0-9]*[\,.]*[0-9]*)/', $string, $matches) If I get a string: 1 - João da Silva number 123456 with the value of R$:6,298.65 I have as return:…
-
1
votes2
answers474
viewsRegular expression to filter the first paragraph between tags using PHP
I need to extract the first paragraph of an HTML code using Regular Expressions. The Goal: To get only the content highlighted in green: HTML code <div class="text"> <p><span…
-
1
votes1
answer38
viewsFetch ID value using preg_match_all in PHP
I get a string in PHP and need to fetch the values of Ids, can be 1, how can be 100 ID’s, how to do? I tried something like this: $texto = 'Nome1 <span id="indicado-b">Camila</span>…
-
1
votes1
answer176
viewsHow to do a regex to take from bar (/) to _, ie I just want the digits before _
/dir/user/Desktop/zip/1_0.zip /dir/user/Desktop/zip/2_0.zip I want to capture only the numbers in bold. I am doing the following and sending to a foreach but it’s not capturing right:…
-
1
votes2
answers327
viewsI’m having trouble picking a value between two strings in PHP using REGEX
$exemplo = "Olá, como vocês estão? Eu queria pegar o valor entre esses colchetes {# Olá mundo} e que esse aqui {#Teste} não interferisse, e me retornasse:"; I’d like the code to return: [ [0] =>…
-
1
votes2
answers1248
viewsExpression to treat URL with parameter
NOTIFYING The solutions below, only will not have great serventias, with them it is necessary to have previously already implemented URL friendly, and also checks of display of the contents of the…
-
1
votes1
answer93
viewsRegex separates by type of occurrences, how to do and the simple way to achieve?
Hello, I am working with user-agent and would like a help. I want to separate a value from a string that has this pattern: Mozilla/<version> (<system-information>) <platform>…
-
1
votes0
answers114
viewsIgnore some fields with regex
In PHP I’m using preg_match_all to get some data from this form: <form id="login_form" action="/login/device-based/regular/login/?login_attempt=1&lwv=100" method="post" onsubmit="">…
-
1
votes1
answer88
viewspreg_match_all does not return all values
I need to get the page titles of a txt but can’t get the correct output values with preg_match_all, always returns me only the result of the last IP line of the.txt file. My code: <?php $arquivo…
-
0
votes1
answer572
viewsPicking with preg_match e-mail with special PHP characters
With this code below it does not take emails with underline. It is possible to modify to it catch including underline and other special characters? In the example below it returns the value…
-
0
votes1
answer902
viewsAbout Regular Expression in PHP - How to Get Part of a Text?
I’m having trouble picking up part of a text from a page on Wikipedia. I can hold the title that way: $content = file_get_contenst("https://en.wikipedia.org/wiki/Nature_conservation");…
-
0
votes1
answer57
viewsYou’re denying access to even normal characters
This command line is not letting my form access the database even with all normal characters someone who understands more than preg_match can help me?…
-
0
votes1
answer216
viewspreg_match_all, regular expression in php with variables
Hello I’m having difficulties in mounting the regular expression, and the function returns me 3 positions in the array all empty; preg_match_all('/<a data-role\="sku\"…
-
0
votes1
answer247
viewsREGEX to get information inside a string
I’m studying PHP OO and part of my study is building a Class that works on a template engine. I converted the file to a string with file_get_contents and now I want to take a part of this string to…
-
0
votes1
answer277
viewsPreg_match c/ Regular expression
I need to remove everything around the link below. I’m using preg_match with regular expression, and as I’m new in the area, I’m having a hard time finding my mistake. Would you please help me? Like…
-
0
votes2
answers3832
viewsHow to use the PHP preg_match command
How do I use the preg_match to detect a string where you have to start with "/command"? This function, for me, is very complicated to understand... I wanted to detect a /command at the beginning of…
-
0
votes2
answers910
viewsCatch DDD nos (11) with regex
I need to get the DDD that’s between the paretenses: (11) 9.9999-9999 I tried to make a regex but I was not successful. I will use PHP to get it, but I needed a regex for it. Could someone give me a…
-
0
votes2
answers32
viewsphp fetch <p> content
How can I catch the 'Valoor' <p id="sinopse2" style="display:block !important;">VALOOR</p> I tried that code: preg_match_all("#<p id=\"sinopse2\">(.*?)<\/p>#s", $string,…
-
0
votes2
answers225
viewsHow to use preg_match() to catch a link within a Javascript code
Hello, I’m making one file_get_contents() in PHP and getting a JS, in this javascript has a code where it contains: $("#download-botao").attr("href", "link.com"); I’m wanting to get this link.com in…
-
0
votes1
answer33
viewsNegative lookahead in php
What’s wrong with that regular expression? preg_match_all('/{{.*?(?!\|e)}}/',$content,$matches); In the text below it should not take {{Expression|e}} since I am denying the |e in the group (?!\|e)…
-
0
votes2
answers270
viewsTraverse string with PHP and return searched values
I am developing a script that is able to locate certain tags in a string and return all found. The pattern of tag will be: [exibebanner id="300"], being that within id="int" will always be an…
-
-1
votes1
answer543
viewsDisplay contents of the <title> tag of the current page using PHP
Hello, I would like a help to modify the code below: <?php function page_title($url) { $fp = file_get_contents($url); if (!$fp) return null; $res =…
-
-1
votes1
answer40
viewspreg_match to pick words between single quotes and remove blanks from the end of match[1] with the same Pattern is possible?
According to the strings below, using preg_match, I need a Pattern that is able to separate what is inside and outside of simple quotes and remove $match[1] blank spaces from the end of the string.…