preg-match

preg match for repeating or incremental characters

两盒软妹~` 提交于 2019-12-06 07:38:26
问题 I am using preg match to validate password as: (preg_match("/^.*(?=.{5,}).*$/", $password) which accept special characters too. but for some reason, i need to modify it which should accept only alphanumeric minimum 5 characters long and very important that it must not have any repeating or incremental characters like: aaaa or 12345 or abc123 etc . 回答1: if (preg_match( '%^ # Start of string (?!.*(.)\1) # Assert no repeated characters # Assert no sequential digits/characters (?!.*(?:01|12|23|34

PHP - preg_match()

倖福魔咒の 提交于 2019-12-06 05:10:44
问题 Alright, so I want the user to be able to enter every character from A-Z and every number from 0-9, but I don't want them entering "special characters". Code: if (preg_match("/^[a-zA-Z0-9]$/", $user_name)) { #Stuff } How is it possible for it to check all of the characters given, and then check if those were matched? I've tried preg_match_all() , but I didn't honestly understand much of it. Like if a user entered "FaiL65Mal", I want it to allow it and move on. But if they enter "Fail{]^7(,",

Matching multiple occurrence of the same character with preg_match

泪湿孤枕 提交于 2019-12-06 05:06:36
how can i find multiple occurrence of the same character? something like: $maxRepeat = 3; "pool" passes "poool" don't i need this to work for any character, so i guess I'll have to escape special characters like . and \ which characters i have to escape? do you know any good reference to preg_match regexp apart from the one on php.net? You use quantifiers for this preg_match("/p(o){1,3}ls/",$string); Excerpt: The following standard quantifiers are recognized: 1. * Match 0 or more times 2. + Match 1 or more times 3. ? Match 1 or 0 times 4. {n} Match exactly n times 5. {n,} Match at least n

How major websites capture thumbnails from a link?

限于喜欢 提交于 2019-12-06 04:18:52
问题 When sharing a link in major websites like Digg and Facebook; it will create thumbnails by capturing main images of the page. How they catch images from a webpage? Does it included loading the whole page (e.g. by cURL) and parsing it (e.g. with preg_match) ? To me, this method is slow and unreliable. Does they have a more practical method? P.S. I think there should be a practical method for quick crawling the page by skipping some parts (e.g. CSS and JS) to reach src attributes. Any idea? 回答1

Regex pattern using w.* not matching text starting with foreign characters such as Ä

╄→尐↘猪︶ㄣ 提交于 2019-12-06 01:39:07
问题 I have the following regex that I have been using successfully: preg_match_all('/(\d+)\n(\w.*)\n(\d{3}\.\d{3}\.\d{2})\n(\d.*)\n(\d.*)/', $text, $matches) However I have just found that if the text that the (\w.*) part matches starts with a foreign character such as Ä , then it doesn't match anything. Can anyone help me with what the correct pattern should be instead of (\w.*) to match a string that starts with any character? Many thanks 回答1: If you do want to match umlauts, then add the regex

PHP preg_match any character except word [duplicate]

一世执手 提交于 2019-12-05 17:44:15
This question already has an answer here: Regular expression to match a line that doesn't contain a word 29 answers Regular Expression block negation 1 answer To match any character except specified character (in this example "f") I use [^f]+ . But how to match any character except specified word? Something like [^word]+ Example: haystack : "bla1 bla2 bla3 bla4 hello bla5 bla6 bla7" (haystack contains HTML and newlines) needle : "bla1 bla2 bla3 bla4 " So I want to catch everything from start untill "hello" The linked possible duplicate is about matching a row that does not contain a specified

Trying To Find Forward Slash In Preg_Match

落爺英雄遲暮 提交于 2019-12-05 14:24:35
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}+$/", $samplerequesturi) preg_match("/^[\\/]{1}[a-z][\\/]{1}[0-9]{11}+$/", $samplerequesturi) preg_match("/^#/#{1}[a-z]#/#{1}

Preg_match PHP to java translation

回眸只為那壹抹淺笑 提交于 2019-12-05 11:49:46
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(); return b; } if (pregMatch(pattern, line)) { //DO ACTION } So my test input is: DBA40365-7346-4DB4-A2CF

Regular Expression to match unlimited number of options

Deadly 提交于 2019-12-05 07:50:58
I want to be able to parse file paths like this one: /var/www/index.(htm|html|php|shtml) into an ordered array: array("htm", "html", "php", "shtml") and then produce a list of alternatives: /var/www/index.htm /var/www/index.html /var/www/index.php /var/www/index.shtml Right now, I have a preg_match statement that can split two alternatives: preg_match_all ("/\(([^)]*)\|([^)]*)\)/", $path_resource, $matches); Could somebody give me a pointer how to extend this to accept an unlimited number of alternatives (at least two)? Just regarding the regular expression, the rest I can deal with. The rule

preg_replace change link from href

…衆ロ難τιáo~ 提交于 2019-12-05 06:15:12
问题 I need to replace urls in the page taken by curl and add correct link to images and links. My php curl code is: <?php $result = '<a href="http://host.org"><img src="./sec.png"></a> <link href="./styles.css" rel="alternate stylesheet" type="text/css" /> <script type="text/javascript" src="./style.js"></script>'; echo $result; if (!preg_match('/src="https?:\/\/"/', $result)) { $result = preg_replace('/src="(http:\/\/([^\/]+)\/)?([^"]+)"/', "src=\"http://google.com/\\3\"", $result); } echo