小编use*_*415的帖子

PHP:从数组中的值中删除正则表达式字符串

我有一个数组$text:

Array
(
    [0] => "(This is so cool!)"
    [1] => "look at @[48382669205:275:JAY Z] and @[28940545600:27:Beyonc\303\251]'s page"
    [2] => "@[30042869909:32:Van Jones] on Bowe Bergdahl drama"    
)
Run Code Online (Sandbox Code Playgroud)

我想匹配删除@ [0-9]文本,所以我的输出如下:

Array
(
    [0] => "(This is so cool!)"
    [1] => "look at JAY Z and Beyonc\303\251's page"
    [2] => "Van Jones on Bowe Bergdahl drama"    
)
Run Code Online (Sandbox Code Playgroud)

我尝试了很多东西(preg_replace等),但这个正则表达式是如此棘手,我无法得到我想要的结果!任何帮助表示赞赏.

php regex arrays

2
推荐指数
1
解决办法
89
查看次数

为什么我的正则表达式与C和下一个字母不匹配?

我的测试文件是:

PolicyChain:ComplementaryUser Caught
PolicyChain:SourceIP Caught
Run Code Online (Sandbox Code Playgroud)

我的正则表达式是:

cat testfile | grep -E -o '[^PolicyChain:].+?'
Run Code Online (Sandbox Code Playgroud)

它匹配:

mplementaryUser Caught
SourceIP Caught
Run Code Online (Sandbox Code Playgroud)

我最终只是想在冒号后但在空格之前匹配字符串.请帮忙??

regex unix

1
推荐指数
1
解决办法
59
查看次数

检查行是否以标点符号结尾; 如果没有,请添加期间

我想检查一行是否以标点符号(.,?!)结尾,如果没有,则添加句点.

A button is missing!
A button on their back allowed them to hug
A cat is carried by the scruff of its neck by a teenage boy?
A cattery is where cats are commercially housed
Run Code Online (Sandbox Code Playgroud)

输出:

A button is missing!
A button on their back allowed them to hug.
A cat is carried by the scruff of its neck by a teenage boy?
A cattery is where cats are commercially housed.
Run Code Online (Sandbox Code Playgroud)

我真的很难过,我试着点击一个字符串的最后一个字符 - 任何帮助?

unix bash

1
推荐指数
1
解决办法
769
查看次数

Python:替换字典值中的单个字符

对于匹配的if条件,如何为Python字典替换字符串中的单个字符?

鉴于:

if key[-1] == "d" and val[-1] == "t":
  print key, val

versed v3rst
vexed vEkst
voiced vOIst
Run Code Online (Sandbox Code Playgroud)

我想把最后一个字母"t"改为"d".我试过了:

if key[-1] == "d" and val[-1] == "t":
  val[-1] = val[-1].replace("t", "d")
  print key, val
Run Code Online (Sandbox Code Playgroud)

但是我得到错误:

val[-1] = val[-1].replace("t", "d")
TypeError: 'str' object does not support item assignment
Run Code Online (Sandbox Code Playgroud)

有小费吗?这似乎是一个简单的if和replace.

python string dictionary replace

1
推荐指数
1
解决办法
956
查看次数

SQL:如何从唯一条目中获取唯一计数?

简单的 SQL 问题,我搜索了但似乎找不到已经提出的答案。

我想查询名称,然后查询每个名称的唯一 url 计数。

输入:

NAME       URL
John       google.com
John       google.com
John       youtube.com
Bob        youtube.com
Bob        twitter.com
Run Code Online (Sandbox Code Playgroud)

期望的输出:

NAME       URL_count
John       2
Bob        2
Run Code Online (Sandbox Code Playgroud)

我试过:

SELECT DISTINCT(name), COUNT(URL) as URL_count
FROM database_table
WHERE date='2013-06-12'
Run Code Online (Sandbox Code Playgroud)

似乎没有产生我需要的结果!帮助?

sql count

0
推荐指数
1
解决办法
4261
查看次数

确保每一行以标点符号结尾

我从nltk抓取了文本语料库,现在想要处理它以确保文件中的每一行都以标点符号结束.

Her mother
had died too long ago for her to
remember her caresses; and her place had been supplied
by an excellent woman as governess, who had fallen little short
of a mother in affection.
Run Code Online (Sandbox Code Playgroud)

应该成为:

Her mother had died too long ago for her to remember her caresses; 
and her place had been supplied by an excellent woman as governess, who had fallen little short of a mother in affection.
Run Code Online (Sandbox Code Playgroud)

我试过匹配,如果在行尾没有标点符号,但无法弄清楚如何向上移动下一行.非常感谢任何帮助!

python unix nltk

0
推荐指数
1
解决办法
111
查看次数

标签 统计

unix ×3

python ×2

regex ×2

arrays ×1

bash ×1

count ×1

dictionary ×1

nltk ×1

php ×1

replace ×1

sql ×1

string ×1