首页 \ 问答 \ Groovy正则表达式/模式匹配(Groovy regex/pattern matching)

Groovy正则表达式/模式匹配(Groovy regex/pattern matching)

我们如何在groovy中进行正则表达式匹配,在下面的示例中,groovy中的正则表达式是什么?

Example : f2376 Regex: (anyLetter)(followed by 4 digits)

How do we do regex matching in groovy, what will be the regex in groovy for below example?

Example : f2376 Regex: (anyLetter)(followed by 4 digits)

原文:https://stackoverflow.com/questions/7772497
更新时间:2023-11-19 13:11

最满意答案

正如iainn评论的问题是,PHP服务器在加载后缓存文件,而不是在第二次需要时从光盘重新调用文件,而是从它的内存缓存中调用它。

如你所说:

“文件内容发生变化”

那么问题是内容没有传递给脚本,而是使用旧内容的内存

因此,调用clearstatcache()强制清除缓存的文件数据。 这应该在写入新数据以更新文件之后,以及在第二次调用文件之前放置。

如果这不起作用,则文件数据可以缓存在其路由中的其他位置。

<?php

    $oldValue = require 'file.php';
    $now = new DateTime();
    $handle = fopen('file.php', "w");
    fputs($handle, "<?php\nreturn '" . $now->format('Y-m-d H:i:s') . "';");
    fclose($handle);
    clearstatcache();           // THIS line should help you 
    $newValue = require 'file.php';

    echo "Old value: $oldValue ";
    echo "New value: $newValue ";
?>

  • 正如iainn所述, opcache_invalidate()可能是一个更具体/更不通用的解决方案。

As commented by iainn The issue is that the PHP server is caching the file once it's loaded and is not re-calling the file from disc on the second require, instead calling it from it's memory cache.

As you have stated that:

"the content of the file changes "

then the issue is the new contents are not passed to the script, instead using the memory of the older contents.

Therefore call clearstatcache() to force clear the cached file data. This should be placed after the new data is written to update the file, and before the file is called for a second time.

If this does not work then the file data may be cached elsewhere in its route.

<?php

    $oldValue = require 'file.php';
    $now = new DateTime();
    $handle = fopen('file.php', "w");
    fputs($handle, "<?php\nreturn '" . $now->format('Y-m-d H:i:s') . "';");
    fclose($handle);
    clearstatcache();           // THIS line should help you 
    $newValue = require 'file.php';

    echo "Old value: $oldValue ";
    echo "New value: $newValue ";
?>

相关问答

更多
  • include / include_once和require / require_once之间的区别在于,当未找到文件时,前者触发警告,而后者触发错误。 意见可能会有所不同,但是由于某些原因,如果需要的文件不存在或不可读,则IMO将表示非常破裂的情况,我宁愿看到错误并停止执行,而不是发出警告,并在明显破坏的上下文中继续执行。 所以我认为最好的做法是专门使用require / require_once并避免include / include_once 。 The difference between incl ...
  • $path = realpath(dirname(__FILE__)) . "/../../parts/mypartsA/main.php"; require_once($path); 尝试这条路 $path = "../parts/mypartsA/main.php"; 第二个路径应该与文档根一起使用。 $path = realpath(dirname(__FILE__)) . "/../../parts/mypartsA/main.php"; require_once($path); try wi ...
  • 正如iainn所评论的问题是,PHP服务器在加载后缓存文件,而不是在第二次需要时从光盘重新调用文件,而是从它的内存缓存中调用它。 如你所说: “文件内容发生变化” 那么问题是新内容没有传递给脚本,而是使用旧内容的内存 。 因此,调用clearstatcache()强制清除缓存的文件数据。 这应该在写入新数据以更新文件之后,以及在第二次调用文件之前放置。 如果这不起作用,则文件数据可以缓存在其路由中的其他位置。
  • 您的问题可能只是函数的范围不会自动包含全局变量。 尝试将$a设置$a global $a; ,以下示例为您的get_header()函数: function get_header(){ global $a; // Sets $a to global scope require('./tpl/header.php'); } Your issue is probably just scope of a function does not automatically include global ...
  • 您对两个文件都处理的原始假设是错误的。 将忽略从未执行的代码块内的include语句。 您可以通过在未执行的分支中的include文件中添加语法错误来确定这是真的。 我做了: testinclude.php:
  • 由于没有人有足够的知识,想花时间解决这个问题,我相信这很容易解决,我现在解决了,后期希望能找到对我这个领域的其他初学者有用! 我回到了第一种方法。 这种方法简单得多,并提供了以下几个步骤:page1 achor click> page1 js var for path和asign to intermediate filed in page1> js使用filePath在page2中加载page3。 过早刷新的问题修复如下:首先将JS文件拆分为三个文件的所有代码,分别为每个页面三个代码,并将setTimeou ...
  • 这是我的设置脚本 #!/bin/bash mkdir -p /etc/php7 mkdir -p /etc/php7/cli git clone https://github.com/php/php-src.git -b PHP-7.0.17 --depth=1 cd php-src/ext git clone https://github.com/krakjoe/pthreads -b master pthreads cd .. ./buildconf --force ./configure - ...
  • 你可以从GPC创建自己的全局变量: foreach (['_GET', '_POST', '_COOKIE'] as $source) { foreach ($$source as $key => $value) { $GLOBALS[$key] = $value; } } 免责声明:不要真的这样做。 So I came up with a temporary solution in the meantime. We utilize an include often in ...
  • 您只需重新启动Apache(httpd)即可使配置更改生效。 重新启动计算机可以做到这一点,但您也可以在终端中运行: sudo apachectl restart I solved it. If you face this problem, and you sure about that you did everything right, just restart the computer.
  • 快速回答 你应该能够做到这一点: require_once 'db_connect.php'; 此外,信息 require , require_once , include和include_once都是相同的,只有一个例外: require会在失败时发出致命错误,因为include会发出警告。 另外要记住这些实际上是通过php ini include_path指令进行搜索,因此当您尝试包含另一个文件时,php将按照第一个指令的顺序搜索这些目录。 默认情况下,该指令通常如下所示: .:/usr/share/ ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。