用PHP编译正则表达式 [英] Compile regex in PHP

查看:96
本文介绍了用PHP编译正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

PHP中是否有一种编译正则表达式的方法,以便可以将其与多个字符串进行比较而无需重复编译过程?其他主要语言也可以做到这一点-Java,C#,Python,Javascript等.

Is there a way in PHP to compile a regular expression, so that it can then be compared to multiple strings without repeating the compilation process? Other major languages can do this -- Java, C#, Python, Javascript, etc.

推荐答案

Perl兼容的正则表达式库可能已经针对您的用例进行了优化,而没有像其他语言一样提供Regex类:

The Perl-Compatible Regular Expressions library may have already be optimized for your use case without providing a Regex class like other languages do:

此扩展程序维护编译后的正则表达式的全局每线程缓存(最多4096个).

This extension maintains a global per-thread cache of compiled regular expressions (up to 4096).

PCRE简介

Imran 所描述的学习修饰符可以在其中存储编译后的表达式电话.

This is how the study modifier which Imran described can store the compiled expression between calls.

这篇关于用PHP编译正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆