- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我想要一个正则表达式来确保字符串的开头包含“http://”和“/”以及结尾。
这是我想出的一个更长的版本,
if(!preg_match("/(^http:\/\//", $site_http))
{
$error = true;
echo '<error elementid="site_http" message="site_http - Your link appears to be invalid. Please confirm that your link contains http:// at the start."/>';
}
elseif (!preg_match("/\/$/", $site_http))
{
$error = true;
echo '<error elementid="site_http" message="site_http - Your link appears to be invalid. Please confirm that your link has ended with a /."/>';
}
但我认为这两个表达式可以像下面这样放在一起,但它行不通,
if(!preg_match("/(^http:\/\/)&(\/$)/", $site_http))
{
$error = true;
echo '<error elementid="site_http" message="site_http - Your link appears to be invalid. Please confirm that your link contains http:// at the start and a / at the end."/>';
}
我尝试组合的多个表达式一定是错误的!有什么想法吗?
谢谢,刘
最佳答案
if(preg_match('/^http:\/\/.*\/$/', $site_http))
{
...
}
^http:\/\/
在前面强制使用 http://
,\/$
在前面强制使用斜杠结束,.*
允许介于两者之间的所有内容(也可能没有)。
例如:
<?php
foreach (array("http://site.com.invalid/", "http://") as $site_http) {
echo "$site_http - ";
if (preg_match('/^http:\/\/.*\/$/', $site_http)) {
echo "match\n";
}
else {
echo "no match\n";
}
}
?>
生成以下输出:
http://site.com.invalid/ - matchhttp:// - no match
关于php - preg_match : ensure the start and the end contains something,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3498591/
我的模型中有一个在私有(private)方法中运行的简单方法: def with_time_zone(zone) @old_time_zone = Time.zone Time.zone =
我想了解如何在代码中使用 Ensures()。正如 example 中给出的那样,如果我尝试使用 Ensures() 如下... int main(void) { int result = 0
当一个方法结束工作时我们也许需要进行清理工作.也许一个打开的文件需要关闭,缓冲区的数据应清空等等.如果对于每一个方法这里永远只有一个退出点,我们可以心安理得地将我们的清理代码放在一个地方并知道它会被
问题 我想检查 R 中的函数工厂是否“安全”。这里的“安全”意味着工厂创建的函数的结果仅取决于它们的参数,而不取决于全局变量。 描述 这是一个不安全的工厂: funfac_bad = function
如果我们有不同的由 webpack 创建的包并且我们 require.ensure在稍后的时间点动态传输+评估它的东西,它通过 jsonPadding 和一些 webpack js 魔法发生。如果我们
我正在开发一个小型 REST API。当我开始分析所有可能的故障场景(我必须处理这些故障场景以创建可靠且稳定的系统)时,我开始思考如何使我的 API 原子化。 如果我们采用通过 POST API 创建
我在 Xor 上有这段代码猫的对象 Xor.right(data).ensure(List(s"$name cannot be blank"))(_.nonEmpty) 现在由于 Xor 已被删除,我
我有一个带有 out 参数的方法,我想使用 Contract.Ensures() 指定当方法返回时,参数不会是 空。 基本上,这是: void M(out object o) { Contra
我开始使用 Code Contracts,虽然 Contract.Requires 非常简单,但我很难理解 Ensures 的实际作用。 我试过创建一个像这样的简单方法: static void Ma
我有一个问题 当我添加一些依赖项时,例如 github.com/jmoiron/sqlx 这个依赖项,我必须等待很长时间,然后它什么都不做,只显示消息“Fetching Sources” 我已经等了
我正在构建一个依赖预定作业的 Heroku 应用程序。我们以前使用 Heroku Scheduler,但时钟进程似乎更加灵活和健壮。所以现在我们使用时钟进程在特定时间/间隔将后台作业排入队列。 Her
我在 Scala 中有一个打字问题的小问题。在 Haskell 中,我可以这样做: add :: (Num a) => (a,a) -> (a,a) -> (a,a) 这样,我就可以扔进add任何支持
这是一个负责与服务器通信的类: public abstract class AbstractCommunicationChannel implements Runnable { static
我不明白为什么静态检查器说这个方法一切正常: public static int GetNonNegativeValue() { Contract.Ensures(Contract.Resul
关闭。这个问题是not reproducible or was caused by typos .它目前不接受答案。 这个问题是由于错别字或无法再重现的问题引起的。虽然类似的问题可能是on-topi
我有一个在 eventmachine react 器中运行的服务器,它监听用户的心跳以判断他们是否在线。当它开始/停止接收心跳时,它会适本地将用户标记为在线和离线。 我想将它全部包装在一个 ensur
我正在使用假设来测试将两个等长列表作为输入的函数。 import hypothesis.strategies as st from hypothesis import assume, given @g
假设我有这个: [Pure] public static TimeSpan Seconds(this int i) { Contract.Ensures(Contract.Result() =
这个问题在这里已经有了答案: How to specify types not allowed in a .NET Generics constraint? (4 个答案) 关闭 8 年前。 我有一
我的 .Net 4 应用程序中有以下代码: static void Main(string[] args) { Func(); } static string S = "1"; static
我是一名优秀的程序员,十分优秀!