开发者

Matching a function name

开发者 https://www.devze.com 2023-01-13 20:10 出处:网络
I need a regex that matches all instances of a particular PHP function name in given a piece of code.

I need a regex that matches all instances of a particular PHP function name in given a piece of code.

The regex should match foo开发者_如何学编程 in:

foo("qwe");
function foo($param);
return foo();

An not match foo in:

my_foo("qwe");
foo_bar();
"some foo string"


Try \bfoo\([^\)]*\). This will match "some foo() string" but not "some foo string" though. Don't know if that's good enough for you.


You will want this:

/\bfoo\b/

The \b checks for word boundary. Basically the start or end of a word (which why it's on both sides).

0

精彩评论

暂无评论...
验证码 换一张
取 消