-
Posts
969 -
Joined
-
Last visited
Posts posted by Destramic
-
-
sorry i meaning zero or one time ---> ?
this returns my match perfectly
$pattern = '#(?<=/)(([ahis]?)\w+))?(\(([\w-]+(?:\|[\w-]+)*)\))?(\*)?(?![^\[\]]*\])#'; if (preg_match_all($pattern, '/news/:action(add|delete|edit)/:type', $matches)) { print_r($matches); }but becuase of the ? zero or one, this subject (/test[/hello[/bye]]) will return matches because of the /
$pattern = '#(?<=/)(([ahis]?)\w+))?(\(([\w-]+(?:\|[\w-]+)*)\))?(\*)?(?![^\[\]]*\])#'; if (preg_match_all($pattern, '/test[/hello[/bye]]', $matches)) { print_r($matches); }what i'm asking is there a way of making my pattern look for:
/(with at least one of the zero or one groups)
or else don't match
i just don't want the regex pattern to match on a /
hope i made myself a bit more clearer
thank you
-
is the directory you trying to move the file to writable? or does the dir exist?...do you have any errors?
-
in my regex pattern i have a lot of none or many operators (?) , which has caused a bit of a problem, as a string containing a forward slash will come back with a result.
(?<=/)(([ahis]?)\w+))?(\(([\w-]+(?:\|[\w-]+)*)\))?(\*)?(?![^\[\]]*\])
is it possible to match with a string containing at lease on for the one or many groups? and not just a forward slash?
$pattern = '#(?<=/)(([ahis]?)\w+))?(\(([\w-]+(?:\|[\w-]+)*)\))?(\*)?(?![^\[\]]*\])#'; if (preg_match_all($pattern, '/news/:action(add|delete|edit)/:type', $matches)) { print_r($matches); // wanted match } if (preg_match_all($pattern, '/test[/hello[/bye]]', $matches)) { print_r($matches); // unwanted match }i'm not able to find evidence that such thing exists, but it's worth an ask.
the reason i bundled all of my routing patterns into one regex pattern is so that i have one simple method to phase all route variables.
giving me a nice array to work with:
Array ( [0] => Array ( [0] => / [1] => /:action(add|delete|edit) [2] => /:type ) [1] => Array ( [0] => [1] => :action [2] => :type ) [2] => Array ( [0] => [1] => [2] => ) [3] => Array ( [0] => [1] => action [2] => type ) [4] => Array ( [0] => [1] => (add|delete|edit) [2] => ) [5] => Array ( [0] => [1] => add|delete|edit [2] => ) [6] => Array ( [0] => [1] => [2] => ) )private function variables() { $pattern = self::ROUTE_VARIABLES; $parameters = $this->match($pattern); if ($parameters) { $count = count($parameters[0]); $route_split = explode('/', $this->_route); $uri_split = explode('/', $this->_uri); for ($i = 0; $i < $count; $i++) { $match = $parameters[0][$i]; $type = $parameters[2][$i]; $name = $parameters[3][$i]; $key = $this->array_search($match, $route_split); if (!isset($uri_split[$key])) { return false; } $value = $uri_split[$key]; if (!empty($parameters[5][$i])) { $values = explode('|', $parameters[5][$i]); if (!in_array($value, $values)) { return false; } else if (empty($name)) { $this->_route = $this->replace($match, $value, $this->_route); continue; } } else if (!empty($parameters[6][$i])) { if (empty($parameters[1][$i])) { $this->_route = $this->replace($match, '(.*)', $this->_route); continue; } else { $next_key = $key + 1; if (!isset($route_split[$next_key])) { return false; } $next_value = $route_split[$next_key]; $values = array(); for ($j = $key; $j < count($uri_split); $j++) { if ($uri_split[$j] === $next_value) { break; } $values[] = $uri_split[$j]; } $value = implode('/', $values); } } if ((!empty($type) && !$this->is_type($value, $type))) { return false; } $replace = '(?P<' . $name . '>'. $value . '+)'; $this->_route = $this->replace($match, $replace, $this->_route); } } return true; }thank you
-
sounds like you havent got jquery included
https://developers.google.com/speed/libraries/
latest:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.0.0/jquery.min.js"></script>
-
thanks guys for you replies...just what i'm after!
@phscho yours returned an error
Error Code: 1235. This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'
strange really as my workbench is up to date
also
Error Code: 1175. You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column To disable safe mode, toggle the option in Preferences -> SQL Editor and reconnect.
i had to turn off safe updates on my mysql workbench...not sure if that is a mysql workbench thing or i would still have gotten the same error if i hadn't of turned off and executed from my php script?
thanks again much appreciated
-
hey guys i'm trying to delete all rows but the latest 6 but i'm having some trouble with the query if you could please help.
i've done some reading and have been llooking at simular queries to what i'm after, but i'm not succeeding.
here is what i have so far:
DELETE FROM benchmarks WHERE ( SELECT count(benchmark_id) FROM benchmarks WHERE name = 'Framework' ORDER BY timestamp ASC ) < 6the error i get is:
Error Code: 1093. You can't specify target table 'benchmarks' for update in FROM clauseany help on where i'm going wrong would be great.
thank you guys
-
wel i feel a lot wiser now...thank you for the breakdown and all your help requinix

-
Why did I just say all that? Because at 4:30am I'm not seeing a "nice" way of solving your particular problem of dealing with the []s.
for 4:30am you've come up with some good solutions

i do like the first option and it does get rid of the bother caused by the brackets and you've openned my mind up to another soltion, thank you...options 2 is what i'm currently doing at the moment.
although my regex knowledge is poor could you please explain to me how i can make this pattern match multiple please?
$uri = "/i:news_id/:hello"; if (preg_match_all('/^\/(i|a|h)?[A-Za-z0-9_]+)$/', $uri, $parameters)) { print_r($parameters); }thank you for your great information
-
well my routing system may contain something like this:
/search/xbox[/category/:category]
matching:
/search/xbox
/search/xbox/category/consoles
so i decided to make my pattern a bit stonger so it match uri vars which are not inside brackets...so yeah my pattern has changed slightly...with the regex in this posts and the others i'm working on i get the problem of matching multiple patterns in the same string...this is my only problem.
can you please tell me where i'm going wrong...thank you
-
i'm sorry for having to post a simular thread but i'm really struggling to get my pattern to work after many attempts...i've tried playing around with it but its just not matching multiple patterns

this will work great
$uri = "/i:news_id"; if (preg_match_all('/(??!\[\/).)*^\/(i|a|h)?[A-Za-z0-9_]+)$(??!\]))/', $uri, $parameters)) { print_r($parameters); }but when chaging this part of the code it won't work
$uri = "/i:news_id/:hello";
examples of matching are:
/:test
/i:test
/a:test
/b:test
but i only want a match as long as the pattern isn't wrapped inside brakcets [ ]
invalid:
[/:test]
i thought the ^ start and $ end characters would have been all i needed...any advise wouldnt greatful...thank you
-
brilliant thank you very much requinix.
i used this pattern which seems to work fine
/(i|s)+:+([A-Za-z0-9_-]\w*)/
-
hey guys, i'm trying to get back in to the swing of things after a lot of time out from programming, and i'm struggling with this simple regex pattern if i could get some help please.
i've decided to go over some of my code and try and re-write things better....starting with my framework.
here is my pattern:
/^\/?(i|s)?:+([A-Za-z0-9_-])$/
what im trying to do is match:
news/i:news_id - returning strings i (if there) and news_id
as the string is uri it could contain a forward slash at the beginning.
if (preg_match_all('/\/?(i|s)?:+([A-Za-z0-9_-])/', 'my-page/i:foo/:bar', $fixed_parameters)) { print_r($fixed_parameters); }result:
Array ( [0] => Array ( [0] => i:f [1] => /:b ) [1] => Array ( [0] => i [1] => ) [2] => Array ( [0] => f [1] => b ) )idealy what i'd like is a result like this:
Array ( [0] => Array ( [0] => i [1] => foo ) [1] => Array ( [0] => [1] => bar ) )thanks guys

regex none or many ?
in Regex Help
Posted
that is what i need...i come up with:
which is a bit spicy...i don't like how i've had to add
to every options, also a:var(a) will come with a match althoght it shouldn't
i think i'm gonna stop over complicating the pattern and just do each pattern individually
thank you for your help again on this matter