dongqing6661 2011-02-14 08:09
浏览 79
已采纳

大型正则表达式模式:PCRC不会这样做

I have a long list of words that I want to search for in a large string. There are about 500 words and the string is usually around 500K in size.

PCRE throws an error saying preg_match_all: Compilation failed: regular expression is too large at offset 704416

Is there an alternative to this? I know I can recompile PCRE with a higher internal linkage size, but I want to avoid messing around with server packages.

  • 写回答

4条回答 默认 最新

  • dongzongzi0379 2011-02-14 08:37
    关注

    Could you approach the problem from the other direction?

    1. Use regex to clean up your 500K of HTML and pull out all the words into a big-ass array. Something like \b(\w+)\b.. (sorry haven't tested that).

    2. Build a hash table of the 500 words you want to check. Assuming case doesn't matter, you would lowercase (or uppercase) all the words. The hash table could store integers (or some more complex object) to keep track of matches.

    3. Loop through each word from (1), lowercase it, and then match it against your hashtable.

    4. Increment the item in your hash table when it matches.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题