Ask a Question related to PHP Development, Design and Development.
-
Curt Zirzow #1
Re: [PHP] Regex and variable usage
Gerard Samuel <gsam@trini0.org> wrote:
You have single quotes, so php wont expand the variables inside.> Has anyone had any success with using variables in a regex shown below??
>
> $foo = 3;
> $bar = 4;
> preg_match('/^[a-z0-9\-_\.]+\.[a-z0-9]{$foo, $bar}$/', $some_string)
that should work.>
> or even
> preg_match('/^[a-z0-9\-_\.]+\.[a-z0-9]{' . $foo . ', ' . $bar . '}$/',
> $some_string)
but you could do this:
$pattern = "/^[a-z0-9\-_\.]+\.[a-z0-9]{$foo, $bar}\$/";
preg_match($pattern, $some_string)
Curt> but this would work
> preg_match('/^[a-z0-9\-_\.]+\.[a-z0-9]{3,4}$/', $some_string)
>
> Thanks for any pointers..
--
Curt Zirzow Guest
-
traversing a variable with regex instead of a file
Hi everyone This is my first posting to the list, although I've been burried knee deep in perl books for some time and have been doing web... -
Regex - assign to new variable and replace in one line?
This is probably simple for the experienced Perl programmer, but as I am learning, and hours of searching has led to nothing, this one has tied me... -
Regex capture variable scoping
Can someone please help me understand what I'm seeing as a contradiction between a statement in the perlre man page and a bug in a script that just... -
Regex and variable usage
Has anyone had any success with using variables in a regex shown below?? $foo = 3; $bar = 4; preg_match('/^+\.{$foo, $bar}$/', $some_string) ... -
Usage and Benefit of Table Variable
Dear all, Two short question for SQL2K: 1) Can table variables be passed into / out of stored procedure as parameters, just in the same way of... -
Unregistered #2
Re: [PHP] Regex and variable usage
You can use preg_match
preg_match ( pattern, subject [, matches [, flags [, offset]]])
where pattern could ve a String variable.
Source: [url]http://www.webcheatsheet.com/php/regular_expressions.php[/url]Unregistered Guest



Reply With Quote

