- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我在 preg_replace
中使用 '/\s+/'
开关来删除我传入 PHP 数组的 Javascript 代码中的所有空格:
preg_replace('/\s+/', '',
("
function(uploader)
{
if(uploader.files.length > 1)
{
uploader.files.splice(1, uploader.files.length);
apprise('You can not update more than one file at once!', {});
}
}
"))
这是一个非常基本的 Javascript 缩小。在 PHP 文件(源)中,我可以拥有完全可读的函数代码,而在浏览器中,它的页面主体最终像单行字符串:
function(uploader,files){console.log('[PluploadUploadComplete]');console.log(files);},'QueueChanged':function(uploader){if(uploader.files.length>1){uploader.files.splice(1,uploader.files.length);apprise('Youcannotupdatemorethanonefileatonce!',{});}}
如您所见(或预期),这确实会影响引号中的字符串并生成不带空格的消息(例如:Youcannotupdatemorethanonefileatonce!
)。
这个问题有解决办法吗?除了嵌入在单引号中的部分外,我可以删除字符串中所有空格吗?
最佳答案
要匹配单引号内以外的空格字符,请使用:
$regex = "~'[^']*'(*SKIP)(*F)|\s+~";
您可以将其直接弹出到您的 preg_replace()
中。
例如:$replaced = preg_replace($regex,"",$input);
选项 2:多种报价
如果你可能有单引号或双引号,使用这个:
$regex = "~(['"]).*?\1(*SKIP)(*F)|\s+~";
这是如何运作的?
在 |
交替的左侧,我们匹配完整的 “带引号的字符串”
,然后故意失败,并跳到字符串中的下一个位置。在右边,我们匹配任何空格,我们知道它是右边的空格,因为它没有被左边的表达式匹配。
引用
How to match (or replace) a pattern except in situations s1, s2, s3...
关于javascript - 去除引号以外的所有空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24075926/
我已经坚持了好几天了……很抱歉遇到这样的问题,但是我只是F#本身的初学者。由于关于类型提供程序的讨论很多,所以我决定建立一个类型提供程序并撰写一篇有关它的论文。当我开始时,我不知道什么是类型提供程序。
我正在开发LAN项目唤醒功能,但是我想控制局域网中计算机是否打开。但是我不想使用ICMP或WMI(我的网络上有DC)。那么,对于此问题,是否还有其他选择,例如“套接字连接”,请检查特定端口是否正在使用
我们有一个旧的VB6应用程序,该应用程序使用Crystal Reports XI生成打印报告。我们已经通过经验发现,如果Crystal Reports打印引擎选择了错误版本的 usp10.dll (W
我正在尝试获取有效的 Android 权限列表。我知道 http://developer.android.com/reference/android/Manifest.permission.html
嗨,我是 nginx 的新手,我试图在我的服务器(运行 Ubuntu 4)上设置它,它已经运行了 apache。 所以在我 apt-get install 它之后,我尝试启动 nginx。然后我收到这
如何在VB 6中检查对象的类型-除了'TypeName'之外,是否还有其他方法,因为无法通过'TypeName'进行检查,我希望使用类似QuichWatch窗口的方法。 最佳答案 对于对象变量,请使用
我的 JSP 应用程序中有一个错误。发布后我的 session 被清除: YAHOO.util.Connect.asyncRequest('POST', Url, callback, post
我是一名优秀的程序员,十分优秀!