我在使用正则表达式匹配http链接时遇到问题.我有一个模式,我想从网站源代码中提取.源代码有200多行,有很多HTML乱码</html><body... useless links useless images'
我需要的http链接属于这种模式:
<a href"http:www.google.com/....1,1">
<a href"http:www.google.com/....2,2">
<a href"http:www.google.com/....3,3">
Run Code Online (Sandbox Code Playgroud)
我只想获得http链接,它们的独特模式就是结局.请帮助,我已经坚持了几个小时试验gusb,regxpr和grep.
假设我有2个列表
divisor = c(0, 1, 1, 7, 7, 8, 8, 8, 9 )
remainder = c(99, 0, 1, 1, 99, 0, 1, 99, 0)
Run Code Online (Sandbox Code Playgroud)
如果相应的余数不是0,我想要一个divisor 元素为元素+ 1.最终的答案应如下所示:
updated.divisor = (1, 1, 2, 8, 8, 8, 9, 9, 9)
Run Code Online (Sandbox Code Playgroud)
我该如何使用sapply?
到目前为止我有
sapply(remainder, function(x) {
if x != 0{
#divisor = divisor + 1
}
else{
#divisor = divisor + 0
}
}
Run Code Online (Sandbox Code Playgroud)
PS我可能使用嵌套循环,但我希望能够使用它sapply.
我在捕获每行的前6个字符时遇到麻烦。假设我在text.txt中包含以下几行:
this is a sentence
1234567890
string
Run Code Online (Sandbox Code Playgroud)
我想获得前10个字符:
this i
123456
string
Run Code Online (Sandbox Code Playgroud)
我试过跑步 grep -Eo "^[a-zA-Z0-9]*{6}" text.txt
但是grep会在第6个位置循环使用正则表达式,而不是从下一行开始。它最终返回:
this i
s a se
ntence
123456
7890..
Run Code Online (Sandbox Code Playgroud)
我在这里做错了什么?
我有一个简单的函数,reverseWords(),它隐藏了字符串中的单词.例如.输入S ="这是一个字符串"给出"siht si a gnirts"的输出
我想知道这个功能的大O是什么.是O(N),O(N ^ 2)还是O(N*M)?
def reverseWords(S):
# code in Python 2.7
listA = S.split()
output = []
for element in listA:
output.append(element[::-1])
return (" ".join(output))
Run Code Online (Sandbox Code Playgroud)
是O(N),O(N ^ 2)还是O(N*M)?
星号或星号告诉引擎尝试匹配前面的标记零次或多次。加号告诉引擎尝试匹配前面的标记一次或多次。
根据定义,我想知道为什么加号比星号返回更多匹配。
echo "ABC ddd kkk DDD" | grep -Eo "[A-Z]+"
Run Code Online (Sandbox Code Playgroud)
返回
美国广播公司
echo "ABC ddd kkk DDD" | grep -Eo "[A-Z]*"
Run Code Online (Sandbox Code Playgroud)
返回 ABC