我用re模块用python编写了一个脚本,以便从网页中获得不同问题的标题。我在这里的意图是不使用BeautifulSoup,并且仍然能够解析标题。我用模式的方式可以做到这一点。但是,输出看起来不太好。我怎么能只得到问题的标题而没有别的。
下面是我的尝试(使用re.search()):
import requests
import re
link = "https://stackoverflow.com/questions/tagged/web-scraping"
res = requests.get(link).text
for item in res.splitlines
我试图使用nodeJS提供API,数据库使用oracle。我从req.body.detail获得了这样一个对象:
{
title: "How to Have",
content: "<ol><li><b>Lorem ipsum dolor sit amet.</b></li></ol>"
}
那我就知道
const data = JSON.stringify(req.body.detail);
但是表中插入的数据变得没有转义字符串,它变成了喜欢:
{"title
假设我检查是否
$strig = "how can i do this";
在我的数据库中已经存在所有单词顺序选项?比如:“我怎么能做到这一点”或“我能做到这一点”……
我的数据库如下所示:
id string
1 how can i do this
2 hello how are you
3 how i can do this world
4 another title
etc etc
谢谢
我们允许用户在应用程序上发布内容,在这种情况下,用户在post标题中输入%,我们正在运行like查询,从数据库中获取数据。这是邮局桌子上的片段
id | title | short_description | long_description
1 how many % amounts you ---------- --------------
should save -------------- -----------------
我们正在运行的查询:
SELECT
我有一个像这样的$questions = ['how ara you','what are the products','tell me about yourself']数组和一个像这样的$str = 'hello how are you'变量。 如果此变量在该数组中可用,则我显示一个结果。我尝试如下所示。 $match = array_search(strtolower($str), $questions); //here that string match exaclty that time only result i
我试图删除字符串中的最后一个空格。
输入如下:
"hi guys how you doing"
我目前正在做的事情:
$ echo "hi guys how you doing" | sed 's/ \+//1'
当前产出:
"higuys how you doing"
预期产出:
"hi guys how youdoing"
这个字符串--例如,在我的应用程序中,我不知道空格的确切位置,我只知道它在最后一个空白位置。
您知道它是否存在不使用rev命令向后搜索字符串的任何方法吗?
我想从MS SQL server数据库中获取记录,在该数据库中,我具有名为xmlData的XML类型列。 我想用类似于:/record/mark = 5的条件执行查询: Query query = session.createQuery("From Test WHERE xmlData.value('(/record/mark)[1]', 'varchar(max)') like '5'");
List list = query.list(); xmlData列结构: <record>
<name>J
message = 'Hello(/ how{can} wan\';t //opperate+32.5 u&# kj|'
我只需要留下字母a-z,A-Z,数字0-9和空格,所以我必须得到'Hello how can wan t opperate 325 u kj',但是当我使用re.sub('[^\w\d]+', ' ', message)或re.sub('[^A-Za-z0-9]+', ' ', message)时,如何得到'Hello how can wan t oppe
我尝试在第一个'||‘符号之前从数据库中提取前'n’个字符。谁能给出that.Here is table的任何想法
表名->播放列表
fact->column name
PLKIDHYYFFEF||hello||ee
KDKOIJOFRFOFRFRF||how||tt
我一直在用来提取子串
"SELECT * FROM playlist WHERE playlist.fact LIKE %...%";
我不能理解应该保留什么模式
我有一堆变量标签,我正在尝试清理它们。
每个字符串都以诸如"Q1_1 -您多大了?“这样的问题编号开头。
我想删除问题开头之前的所有内容。
输入:"Q1_1 - How old are you?"
输出:"How old are you?"
刚开始使用re.sub并了解如何逐个案例地使用它,但是对于40+变量,我一下子就不知所措了,并且在网上找不到任何有效的东西。
我在网上找到了这个代码,它只是把字符从'_‘替换成了'-':
re.sub('/.*- / ','',myvarlabel)
我有这样的数据:
/some test/ -> next data
prev<-/now/->/how about this/
asd<-/rege\/x/
/\/\//
/\\/
/^\d+$/ <- /\./
/\./ -> /\d/
我想把它分割成\w+|/.*?/,<-,->,但是->和<-不能在/here/里面
我试过,但在这个例子中失败了,/\/\//。
const data = `/some test/ -> next data
prev<-/now/->/how about this/
asd
我正在学习python中的re模块。我发现了一些(对我来说)不合理的东西,我不知道为什么。下面是一个小例子,
x=re.compile(r'(ha)*')
c=x.search('the man know how to hahahaha')
print(c.group())#output will be nothing,no error.But i expect "hahahaha"
如果我使用re.compile(r'(ha)?'),也会发生同样的情况,
x=re.compile(r'(ha)?')
c=x.se
使用此模式:
(how is\s)?(the\s)?(weather)\s?((on)\s)?(today|tomorrow|sunday|monday|tuesday|wednesday|thursday|friday|saturday|sunday|this week)?(\s(in)\s(.*)\s?(on)?\s?(today|tomorrow|sunday|monday|tuesday|wednesday|thursday|friday|saturday|sunday|this week)?)?
这就是我想要捕捉到的
输入:how is the weather on tuesday
我的Ruby脚本有问题。我正在读取文件中的文本,我想删除某些字符。
我的file.rb包含以下内容:print "Hello!" print "How are you?"
解释起来不太容易,下面是代码:
File.open("file.rb").each do |line|
line = line[6..line.length]
line = line[0...-1]
end
这应该会返回:Hello! How are you?
然而,我得到了:Hello!" How are you?
我做了一些测试,发现只有文件中的最后一行字符被移
假设,我有一个字符串:
string="""<p>It is common for content in Arabic, Hebrew, and other languages that use right-to-left scripts to include numerals or include text from other scripts. Both of these typically flow left-to-right within the overall right-to-left context. </p> <p&g
我有一个以路径形式出现的字符串,例如:
Year 1 / English / Writing / How to write your name
我需要生成一个字符串,它是第二个正斜杠之后的所有内容。从上面的例子来看,这意味着我想要的输出是:
Writing / How to write your name
我已经看到了许多关于输出URL的最后部分或在文件路径中获取特定文件夹名的问题/答案,但到目前为止,它们都没有对我有效。我得承认,由于时间限制,我的研究还不够深入。
我的第一个想法是在javascript中这样做,如下所示:
var input = "Year 1 / English
我希望用域("Hello world stackoverflow.com")替换字符串中的URL ("Hello world http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example")。
到目前为止,我可以用一些常量值来标识和替换URL,但不能用URL的域来标识和替换:
x <- "Hello world http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-
如果与列表匹配,我将尝试从字符串中删除单词。
x = "How I Met Your Mother 7x17 (HDTV-LOL) [VTV] - Mon, 20 Feb 2012"
tags = ['HDTV', 'LOL', 'VTV', 'x264', 'DIMENSION', 'XviD', '720P', 'IMMERSE']
print x
for tag in tags:
if tag in x:
print
我正在寻找一种方法来查询多个字段中的值。基本上,我正在建立一个简单的搜索引擎,其中用户可以输入ie。"Java How to XML JSON“,它将在3个不同的字段categories, tags, description中搜索这些值。 我在一些博客上读到,我应该查询所有字段q=*:*,然后根据这些字段进行过滤,例如fq=categories:java,xml,how,to,json description:java,xml,how,to,json tags:java,xml,how,to,json 这是有效的:|但是像这样复制粘贴值似乎是不正确的。 有没有正确的方法来做这件事
(第一篇文章...对编程非常陌生)
我需要将一堆文件从'This is a filename-123456.ext‘重命名为'123456-This is a filename.ext’。
我用下面的代码使用Python设法解决了这个问题。我不得不写两个脚本,因为有时有5个数字,但大多数情况下是6个。
import os
for filename in os.listdir('.'): #not sure how to rename recursive sub-directories
if filename != 'ren6.py': #
如何在列表中找到最近的字符串:
var list = new List<string>
{
"hello how are you",
"weather is good today",
"what is your name",
"what time is it",
"what is your favorite color",
"hello world",
"how much money you got",
我试图创建一个PHP Chatbox,我实现了SQL数据库,如下所示:
ID ID_sender ID_parent content
1 1 0 "Hello Mark"
2 2 1 "How are you Steve ?"
3 3 0 "Hi John, are you still coming tonight ?"
4
例如:
"Hi! How :) are :) you? I'm :) fine.:)".magic()
=> "Hi! How are :) you? I'm fine.:)"
or
=> "Hi! How are :) you? I'm :) fine."
or
...
仅:)应支持删除或替换笑脸。
mongod.conf文件
# mongod.conf
# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/
# Where and how to store data.
storage:
dbPath: /var/lib/mongodb
journal:
enabled: true
# engine:
# mmapv1:
# wiredTiger:
# where to write log
C#中有没有什么函数可以检查两个字符串的相似度百分比?
例如,我有:
var string1="Hello how are you doing";
var string2= " hi, how are you";
和
function(string1, string2)
将返回相似度比率,因为"how“、" are”、"you“出现在行中。
或者更好的是,返回60%的相似度,因为"how","are","you“是string1的3/5。
在C#中有没有这样做的函数?
给定一个纺织品,我如何替换所有在%开头有[]的令牌。例如,在以下文本文件中:
Hi how are you?
I %am %fine.
Thanks %and %you
如何将所有字符与%一起用[]括起来?
Hi how are you?
I [am] [fine].
Thanks [and] [you]
我试着先过滤这些令牌,然后替换它们,但也许有一种更多的仿生方法:
with open('../file') as f:
s = str(f.readlines())
a_list = re.sub(r'(?<=\W)[$]\S*',
让我们考虑一个字符串str,它定义为:
const str = " 'I am going' - 'I' "
和一个函数calc(),它可以用作:
console.log( calc(str) ) // => am going
因此,我决定使用regex使calc()!这就是我所想的。
const calc = (str) => {
const reg = // Not understanding how to get the strings between which '-' falls
str = str.re