我正在试图弄清楚为什么正则表达式不匹配.任何帮助深表感谢.我将逐行浏览网页(工作正常),但我需要为每一行提取链接.应用程序将检查该行中是否有链接,但我需要实际提取URL.救命?
Pattern p = Pattern.compile("^.*href=\"([^\"]*)");
Matcher m = p.matcher(result);
String urlStr = m.group();
links.add(urlStr);
Run Code Online (Sandbox Code Playgroud)
我一直得到的错误信息是这样的:
Exception in thread "main" java.lang.IllegalStateException: No match found
at java.util.regex.Matcher.group(Matcher.java:485)
Run Code Online (Sandbox Code Playgroud)
即使'result'中有一个链接引用(hxxp://www.yahoo.com).
links是一个ArrayList fyi.提前致谢!
我想弄清楚为什么现在它坏了,因为我让它工作了,但我不确定出了什么问题。我正在尝试从已打开的文件中使用简单的 getline,但是,编译器不断给我错误。我试过找其他有这些问题的人,但我找不到其他有这个问题的人。有什么建议吗?
void Foo::bar(ifstream &inputFile)
{
// Read in the data, parse it out, and
// call loadQueue
string input;
do {
getline(inputFile, input);
loadQueue(input);
}while (!(inputFile.eof()));
}
Run Code Online (Sandbox Code Playgroud)
这是我得到的回报:
g++ -c -o Airworthy.o Airworthy.cpp
Foo.cpp: In member function ‘void Airworthy::readData(std::ifstream&)’:
Foo.cpp:25:27: error: no matching function for call to ‘getline(std::ifstream&, std::string&)’
Foo.cpp:25:27: note: candidates are:
In file included from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.2/../../../../include/c++/4.7.2/string:55:0,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.2/../../../../include/c++/4.7.2/bits/locale_classes.h:42,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.2/../../../../include/c++/4.7.2/bits/ios_base.h:43,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.2/../../../../include/c++/4.7.2/ios:43,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.2/../../../../include/c++/4.7.2/ostream:40,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.2/../../../../include/c++/4.7.2/iostream:40,
Run Code Online (Sandbox Code Playgroud)
关于问题是什么的任何想法?