dousi1994 2014-12-11 08:27
浏览 78
已采纳

php shell_exec正则表达式PCRE / POSIX

I have a problem with my php-script when I call shell_exec and pass a regular expression.

PHP code :

shell_exec("sh myscript.sh 'FOO\s*ONE'");

myscript.sh :

result=$(grep -c "${1}"  myLongFile.txt)
echo ${result}

Like this, it returns 0 but if il call directly with cmd grep -c "FOO\s*ONE" myLongFile.txt it returns 23.

And if i replace in my php script \s by the class [[:space:]] it's working, but I have to use \s

I tried many solutions but failed.

  • 写回答

4条回答 默认 最新

  • duandie0921 2014-12-11 08:55
    关注

    Thank you all,

    I find the solution, i just add option -P for grep in my script like this :

    result=$(grep -P -c "${1}"  myLongFile.txt)
    

    Now, i can use \s

    -P, --perl-regexp Interpret PATTERN as a Perl regular expression.

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

报告相同问题?

悬赏问题

  • ¥20 fluent无法启动
  • ¥15 孟德尔随机化r语言运行问题
  • ¥15 pyinstaller编译的时候出现No module named 'imp'
  • ¥15 nirs_kit中打码怎么看(打码文件是csv格式)
  • ¥15 怎么把多于硬盘空间放到根目录下
  • ¥15 Matlab问题解答有两个问题
  • ¥15 LCD12864中文显示
  • ¥15 在使用CH341SER.EXE时不小心把所有驱动文件删除了怎么解决
  • ¥15 gsoap生成onvif框架
  • ¥15 有关sql server business intellige安装,包括SSDT、SSMS。