Regular Expression-Can php match "function" and "class? Realistic

Source: Internet
Author: User
{Code...} has the following effect: Separate the three functions in the string $ str and store them in the array. Is there any good Regular Expression matching method with high compatibility? (Similar) Thank you.

  

The effect is as follows:
Separate the three functions in the string $ str and store them in the array. Is there any good Regular Expression matching method with high compatibility? (Likewise)
Thank you!

Reply content:

   

The effect is as follows:
Separate the three functions in the string $ str and store them in the array. Is there any good Regular Expression matching method with high compatibility? (Likewise)
Thank you!

Please explain the meaning of this first. Why are you doing this?
In addition, based on your questions, I provide some information, hoping to help you

Create an anonymous function in php: create_function
Get_defined_vars returns an array consisting of all Defined variables.

If it is a regular expression, you need to useRegular Expression balancing group.
If your str is regular and does not have function nesting, and there are no other statements between functions, you can use the string splitting method directly.

Regular Expressions are very poor in compatibility. You can use PHP-Parser if you don't have to worry about it.
Https://github.com/nikic/PHP-Parser
PHP-Parser extracts AST and generates code through AST in reverse direction (you need to traverse AST by yourself)
Https://github.com/nikic/PHP-Parser/blob/1.x/doc/4_Code_generation.mar...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.