List Info

Thread: match php code




match php code
user name
2006-02-20 22:26:17
Hello to everybody, this is my first post...

First of all sorry for my english, I'm Italian ;)

I'm Trying to match php code, by preg functions of php, and
I've some
problems.

In Fact is simply to match something like this:
<?php
 echo "hello world;
?>

but is more complicated, for me, to match this one:
<?php
 print "hello?> w\"orld";
 echo "Hello ?> world";
?>

This last snippet is valid php code.
So I've tried something like:

/(<\?php|<\?=|<\?)(.*?(?:('|")(?:(?:\\
3|[^\3])*?\3)*?.*?)*?)(\?>)/s

or

/(<\?php|<\?=|<\?)(.*?(?:('|\")(?:\\\
3|[^\3])*?\3)+.*?)(\?>)/s

nothing to do...

Any ideas?


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Regex" group.
To post to this group, send email to regexgooglegroups.com
To unsubscribe from this group, send email to
regex-unsubscribegooglegroups.com
For more options, visit this group at http://groups.go
ogle.com/group/regex
-~----------~----~----~----~------~----~------~--~---

match php code
user name
2006-02-20 22:56:39
"Epper" <m.eppergmail.com> wrote:
>
>
>Hello to everybody, this is my first post...
>
>First of all sorry for my english, I'm Italian ;)
>
>I'm Trying to match php code, by preg functions of php,
and I've some
>problems.

I'm guessing your problem is with the quotes -- you could
use this to
capture the string with the escaped quote in it:
".+?(?<!\\)"

To capture the entire snippet you could use this regex:
http://tinyurl.com/kxf8l

But that one isn't smart enough to know whether it's
double or single
quotes, that would take a little more tweaking and I'm a
bit in a hurry 
-- basically just capture the first double or single quote
into a
backreference then reference it at the close of the quotes
to make sure
you're matching them.  In this, nothing is pulled into
backreferences, it's
just a quick regex to show how you could capture it.

Also keep in mind that when plugging regex into php, you're
going to have
to double up on backspaces -- so \\ would become \\\\
-- \r would become
\\r etc.


-- 
Remember, no matter where you go, there you are. -Buckaroo
Banzai
Online Regex find/repalce utility: http://rereplace.com
Command-based online image editor: http://theprawn.com/imag
iine

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Regex" group.
To post to this group, send email to regexgooglegroups.com
To unsubscribe from this group, send email to
regex-unsubscribegooglegroups.com
For more options, visit this group at http://groups.go
ogle.com/group/regex
-~----------~----~----~----~------~----~------~--~---

[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )