preg-match

Crontab intervals preg match

核能气质少年 提交于 2020-01-06 15:27:17
问题 Purpose: Trusted user puts up a crontab line, give advice when then syntax is wrong I got this one which seems to work well: /^\s*(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+\S+\s+.+\S*$/ I want to improve (learning purpose) and tried to reduce the \S+\s : /^\s*[(\S+)\s+]{6}.+\S*$/ When you look at typical crontab lines, all its values are seperated by (any amount of) 6 whitespace characters. 2-20/2 10,20 /3 * * user very -long -cryptic > comand ^\s* \S+ \s+ \S+ \s+ \S+ \s+ \S+\s+\S+\s+ \S* $

How can I ignore “XXX” titles in my data parsing script?

依然范特西╮ 提交于 2020-01-06 08:14:11
问题 I've tried and it doesn't seem to work. Any help would be greatly appreciated. CODE: foreach (glob('mov/Alene*.mov') as $filename){ $theData = file_get_contents($filename) or die("Unable to retrieve file data"); } $string = $theData; $titles = explode("\n", $string); function getInfo($string){ $Ratings = ['G', 'PG', 'PG-13', 'R', 'NR', 'XXX']; $split = preg_split("/\"(.+)\"/", $string, 0, PREG_SPLIT_DELIM_CAPTURE); if(count($split) == 3){ preg_match("/(".implode("|", $Ratings).")\s/", $split

preg_match decimals not working

隐身守侯 提交于 2020-01-06 03:04:22
问题 I seem to be having a problem with a preg_match code, I am trying to get the decimal number from a string which should be something like '3.25' but instead I get '1' preg_match('/[0-9]+(?:\.[0-9]*)?/', '£3.25', $matches); echo 'match: '.$matches[0]; prints "1" 回答1: preg_match('#\d+(?:\.\d{1,2})?#', '£2.35', $match); var_dump($match); gives array(1) { [0]=> string(4) "2.35" } even on PHP 5.2 : http://codepad.viper-7.com/9nFhET 回答2: First, you'll find the value at the index 1 of the array (

PHP preg match / replace?

谁说胖子不能爱 提交于 2020-01-06 02:11:19
问题 I need to read the string $mysting and replace all incident of e.x. <img src="dummypic.jpg alt="dummy pic"> with <img src="dummypic.jpg alt="dummy pic" title="dummy pic"> in other words add the title where it is missing, and make the title tag have the same value as the alt tag. some incident my have additional parameters like border, with, height - and these should be left untouched ... 回答1: Rather than a regex, have a look into PHP DOMDocument to modify attributes, especially if there will

PHP - Extract form action url from mailchimp subscribe form code using regex

房东的猫 提交于 2020-01-05 10:30:18
问题 I'm creating a custom mailchimp form template for my users. So I would like to extract ONLY form action url from mailchimp code.. Can someone tell me how to extract action url from the following code. <!-- Begin MailChimp Signup Form --> <div id="mc_embed_signup"> <form action="http://xxxxxxxx.us5.list-manage.com/subscribe/post?u=xxxxxxxxxxxxxxxxxx&id=xxxxxxx" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" target="_blank" novalidate> <h2

PHP preg_match with regular expression: only single hyphens and spaces between words

廉价感情. 提交于 2020-01-05 08:40:09
问题 How can I allow single hyphens and single spaces only within words but not at the beginning or at the end of the words? if(!preg_match('/^[a-zA-Z0-9\-\s]+$/', $pg_tag)) { $error = true; echo '<error elementid="pg_tag" message="TAGS - only alphanumbers and hyphens are allowed."/>'; } I don't want to accept these inputs below ---stack---over---flow--- stack-over-flow- stack-over-flow2 stack over flow but only these are acceptable, stack-over-flow stack-over-flow2 stack-over-flow3 stack over

Warning: preg_match() [function.preg-match]: No ending delimiter '/' found

痞子三分冷 提交于 2020-01-05 07:04:54
问题 when this function was called it gave the message Warning: preg_match() [function.preg-match]: No ending delimiter '/' this is the function to check for alphanumeric input function CheckAlphanumeric($element,$minlength,$maxlength) { if (!preg_match ("/[^A-Za-z\s\0-9 - @ .]//", $element) && strlen($element)>=$minlength && strlen($element) <=$maxlength) { return TRUE; } else { return FALSE;} } What are your inputs on this warning? 回答1: You'll want to escape the last forward slash (or remove it,

Warning: preg_match() [function.preg-match]: No ending delimiter '/' found

折月煮酒 提交于 2020-01-05 07:04:28
问题 when this function was called it gave the message Warning: preg_match() [function.preg-match]: No ending delimiter '/' this is the function to check for alphanumeric input function CheckAlphanumeric($element,$minlength,$maxlength) { if (!preg_match ("/[^A-Za-z\s\0-9 - @ .]//", $element) && strlen($element)>=$minlength && strlen($element) <=$maxlength) { return TRUE; } else { return FALSE;} } What are your inputs on this warning? 回答1: You'll want to escape the last forward slash (or remove it,

preg_match to check if string has specific structure

天大地大妈咪最大 提交于 2020-01-05 05:37:05
问题 How can I check with php with preg_match() if string has specific structure. For example string is: options:blue;white;yellow; I want to check if string starts with string followed by : followed by n-numbers of strings separated by ; And something which is important - string may be in Cyrillic, not only latin letters 回答1: Assuming only the restrictions listed in your question are needed, this will validate the string: $number = 3; $regex = sprintf('/^[^:]+:(?:[^;]+;){%d}$/', $number); if

how to implement template with conditions with preg_replace

≯℡__Kan透↙ 提交于 2020-01-04 14:00:55
问题 I'm trying to implement an admin interface where manager could create advanced rules of site meta tags formation. I have a function which takes a template and replaces placeholders in it with values from $registry and applies modifiers if needed. $registy = array( 'profession_name' => 'actor', 'total_found' => 100, ); $result = preg_replace_callback('/\{([^{}:]+)(:[^{}:]+)?\}/', function($matches) use ($registry) { $result = $registry[$matches[1]] ?: $matches[0]; if (in_array($matches[2],