我正在努力让我的正则表达式匹配。这是我的要求...
将以下域 ex (google.com) 与 http 和 https 匹配。
我有一个包含各种 URL 的数组列表....
http://stackoverflow.com/questions/ask
https://ask.com/search
http://google.com/images
https://google.com/images
这是我的模式:
final Pattern p = Pattern.compile( "(http:(?!.*google.com).*)" );
但是,它目前对我所有的 url 都返回 true。
同样,我只希望它在 http://www.google.com 时返回 true或 https://www.google.com匹配我当前的 url。
最佳答案
使用这个:
Pattern.compile("^(https?://(?![^.]*\\.google\\.com)[^/]*)");
关于Java - 需要一些关于匹配 http 和 https 的正则表达式模式的帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9640818/