preg-match

preg_match returns identical elements only once

风格不统一 提交于 2019-12-07 20:33:50
问题 I am going through a string and proces all the elements between !-- and --!. But only unique elements are processes. When I have !--example--! and a bit further in the text also !--example--!, the second one is ignored. This is the code: while ($do = preg_match("/!--(.*?)--!/", $formtext, $matches)){ I know about preg_match_all, but need to do this with preg_match. Any help? Thanks in advance! 回答1: You'll want PHP to look for matches only after the previous match. For that, you'll need to

How can I extract certain HTML tags e.g. <ul> using Regex with preg_match_all in PHP?

十年热恋 提交于 2019-12-07 19:55:09
问题 I am new to regular expressions. I want to fetch some data from a web page source. I used file_get_contents("url") to get the page's HTML source. Now I want to capture a portion within some special tags. I found preg_match_all() works for this. Now I want some help to solve my problem and if possible help me to find out how to solve similar problems like this. In the example below, how would I get the data within the <ul> ? (I wish this sample HTML code could be easier for me to understand.)

PHP - preg_match - How to match a string upper/lower case with anything before or after it?

丶灬走出姿态 提交于 2019-12-07 15:08:21
问题 I have a part of a function that goes like this: if (preg_match("#\bscript\b#",$userInput)) { $bannedWord = 'script'; logHax(); return TRUE; } This is causing a problem for what I am trying to accomplish because it will only match the exact word "script" and not variations of it, like "ScriPt" or " <script> ". What I would like to have is the examples of the not matched strings along with the original string return true. Could someone provide me with a bit of understanding on this matter.

Preg_match PHP to java translation

给你一囗甜甜゛ 提交于 2019-12-07 11:02:28
问题 I am having some trouble converting a php pregmatch to java. I thought I had it all correct but it doesn't seem to be working. Here is the code: Original PHP: /* Pattern for 44 Character UUID */ $pattern = "([0-9A-F\-]{44})"; if (preg_match($pattern,$content)){ /*DO ACTION*/ } My Java code: final String pattern = "([0-9A-F\\-]{44})"; public static boolean pregMatch(String pattern, String content) { Pattern p = Pattern.compile(pattern); Matcher m = p.matcher(content); boolean b = m.matches();

Trying To Find Forward Slash In Preg_Match

冷暖自知 提交于 2019-12-07 10:31:17
问题 I've been searching for hours trying to find a solution to this. I am trying to determing if the REQUEST URI is legit and break it down from there. $samplerequesturi = "/variable/12345678910"; To determine if it is legit, the first section variable is only letters and is variable in length. The second section is numbers, which should have 11 total. My problem is escaping the forward slash so it is matched in the uri. I've tried: preg_match("/^[\/]{1}[a-z][\/]{1}[0-9]{11}+$/",

PHP Preg_match match exact word

╄→尐↘猪︶ㄣ 提交于 2019-12-07 08:34:30
问题 I have stored as |1|7|11| I need to use preg_match to check |7| is there or |11| is there etc, How do I do this? 回答1: Use the faster strpos if you only need to check for the existence of two numbers. if(strpos($mystring, '|7|') !== FALSE AND strpos($mystring, '|11|') !== FALSE) { // Found them } Or using slower regex to capture the number preg_match('/\|(7|11)\|/', $mystring, $match); Use regexpal to test regexes for free. 回答2: Use \b before and after the expression to match it as a whole

PHP replace string with values from array

断了今生、忘了曾经 提交于 2019-12-07 07:22:09
问题 I have a string such as: Hello <%First Name%> <%Last Name%> welcome and I have a array [0] => Array ( [First Name] => John [Last Name] => Smith ) What I need to do is take the string and replace the words in <% with the actual text from the array So my output would be Hello John Smith welcome Im not sure how to accomplish this but I cant even seem to replace it with regular text $test = str_replace("<%.*%>","test",$textData['text']); Sorry I should of mentioned that the array keys may vary as

PHP 5.2 preg_match() compilation failure

你离开我真会死。 提交于 2019-12-07 06:24:28
问题 Would very much appreciate some help. My hosts server-side updates have caused my comment form to throw two validation errors. First one is: preg_match() returns Warning: preg_match() [function.preg-match]: Compilation failed: range out of order in character class at offset 13 in [script location here and line error] - second is on subject check at offset 14. It does this on the email address check: if (preg_match('/[^a-zA-Z0-9_-.]/', $_POST['txtEmail'])) and subject check: if (preg_match('/[

“preg_match(): Compilation failed: unmatched parentheses” in PHP for valid pattern

人走茶凉 提交于 2019-12-06 23:25:34
问题 Wondering if anyone out there can shed some light on why the following regular expression is failing when used in PHP's preg_match function:- <?php $str = '\tmp\phpDC1C.tmp'; preg_match('|\\tmp\\([A-Za-z0-9]+)|', $str, $matches); print_r($matches); ?> This results in the error message "preg_match(): Compilation failed: unmatched parentheses" despite the fact that the pattern appears to be valid. I've tested it with an online PHP Regular Expression tester and the Linux tool Kiki. Seems like

Regular Expression Help for Date Validation - dd/mm/yyyy - PHP [duplicate]

﹥>﹥吖頭↗ 提交于 2019-12-06 23:19:53
问题 This question already has answers here : preg_match: check birthday format (dd/mm/yyyy) (11 answers) Closed 6 months ago . Can someone show me the error of my ways when it comes to this regular expression: if(preg_match("/^[0-9]{1,2}/[0-9]{1,2}/[0-9]{4}$/", $_POST["date"]) === 0) { echo 'error'; } Basically I want this to display an error message each time - unless the format is correct (dd/mm/yyyy). What am I doing wrong with the above? Many thanks for any pointers. -- updated regex above