regular expression

1.R,strongly recommend this blog

The table_info examples are following:

du_mtime_cinema_showtime20190606

du_amap_shoppingmall_indoor_201903_d4

du_amap_shopping_mall_info_2017

du_amap_ship_201909

I want tables which start with"du_amap_" and end with year/month, so in the tables above,

I only want the fourth one. Below, in R, character escape (the backlash character \) should be \\.

"^"means the start and "$" means the end.

^can delete but $ can't because we use "grep" function.

keyword_all <-'^du_amap_.+2\\d{5}$'
keyword_table <- grep(keyword_all, table_info$Tables_in_risingdata, value =T)

str_extract_all is a function which only filters out the characters that fits the pattern.

The below codes extract the last six numbers:year and month

table_name_body <- 'amap_cvs_citycount'
month<-str_extract_all(string=keyword_table[p],pattern='\\d.+')%>% as.character()

* means the pattern in front of it will appear one or more times, | means or, and . means any characters.

Below codes means deleting "du_amap_" and "_201..".

keyword <- gsub('.*amap_|_201.*', '', table_name_body)
shoppingmall_amap$name<-gsub('(\\(.*\\))',"",shoppingmall_amap$name)

latitude and longtitude

\\d{2}[.]\\d+

find Chinese

[\u4E00-\u9FA5\\s]+ #many characters,including space
[\u4E00-\u9FA5]+ #many characters,not including space
[\u4E00-\u9FA5] #one character

2.Python

import re

查找数字,注意这里python转义只有一个\,但R里转义要两个:\\

pattern1 = re.compile(r'\d+')

这里是找表格里每行以(080)开头的数字

pattern1 = re.compile(r'\(080\)\d+')
fixed_line_all=pd.DataFrame()
for i in range(len(calls_pd[0])):
fixed_line=pattern1.findall(calls_pd[0][i])
fixed_line_all=set(fixed_line_all).union(fixed_line)
fixed_line_all=pd.DataFrame(fixed_line_all)

这里提取以7、8、9开头的前四位数

pattern2=re.compile(r'^(7\d{3}|8\d{3}|9\d{3})')
for i in range(len(fixed_line_bind[1])):
mobile_line=pattern2.findall(fixed_line_bind[1][i])
mobile_bang=set(mobile_bang).union(mobile_line)
mobile_bang=pd.DataFrame(mobile_bang)

正则表达式(R&Python)的更多相关文章

  1. 正则表达式与Python中re模块的使用

    正则表达式与Python中re模块的使用 最近做了点爬虫,正则表达式使用的非常多,用Python做的话会用到re模块. 本文总结一下正则表达式与re模块的基础与使用. 另外,给大家介绍一个在线测试正则 ...

  2. python全栈开发之正则表达式和python的re模块

    正则表达式和python的re模块 python全栈开发,正则表达式,re模块 一 正则表达式 正则表达式(Regular Expression)是一种文本模式,包括普通字符(例如,a 到 z 之间的 ...

  3. (转)正则表达式与Python(RE)模块

    Python正则表达式指南  原文:http://blog.csdn.net/qdx411324962/article/details/46799831 Python3(2):正则表达式与Python ...

  4. 正则表达式r和re

    # coding:utf-8 import re print 'a\ws' print r'a\nb' # r'': 一般用在正则表达式中,称为原始字符串,作用是将Python语法中的反斜杠转义给 取 ...

  5. 一句python,一句R︱python中的字符串操作、中文乱码、NaN情况

    一句python,一句R︱python中的字符串操作.中文乱码.NaN情况 先学了R,最近刚刚上手Python,所以想着将python和R结合起来互相对比来更好理解python.最好就是一句pytho ...

  6. A Complete Tutorial on Tree Based Modeling from Scratch (in R & Python)

    A Complete Tutorial on Tree Based Modeling from Scratch (in R & Python) MACHINE LEARNING PYTHON  ...

  7. 7 Tools for Data Visualization in R, Python, and Julia

    7 Tools for Data Visualization in R, Python, and Julia Last week, some examples of creating visualiz ...

  8. NLP︱高级词向量表达(一)——GloVe(理论、相关测评结果、R&python实现、相关应用)

    有很多改进版的word2vec,但是目前还是word2vec最流行,但是Glove也有很多在提及,笔者在自己实验的时候,发现Glove也还是有很多优点以及可以深入研究对比的地方的,所以对其进行了一定的 ...

  9. 数据科学实战手册(R+Python)书中引用资料网址

    本文会持续将<数据科学实战手册(R+Python)>一书中的附带参考资料网址手打出来, 方便访问. 由于书中的参考资料网址太多, 这个文档将可能花费一段时间才能完成. 第一章 P7  Rs ...

  10. 常用正则表达式与python中的re模块

    正则表达式是一种通用的字符串匹配技术,不会因为编程语言不一样而发生变化. 部分常用正则表达式规则介绍: . 匹配任意的一个字符串,除了\n * 匹配任意字符串0次或者任意次 \w 匹配字母.数字.下划 ...

随机推荐

  1. 安卓权威编程指南 挑战练习 13.8 用于RecyclerView的空视图

    当前,CriminalIntent应用启动后,会显示一个空白列表.从用户体验上来讲,即使crime列表 是空的,也应展示提示或解释类信息. 请设置空视图展示类似“没有crime记录可以显示”的信息.再 ...

  2. sublime安装vue插件

    1.打开sublime text 3按 Ctrl+Shift+P(相信你有单身的手速,同时按完这3个键) 2.选中上图中,框出来的内容,按下enter. 3.选择上图的第二个即:vue syntax ...

  3. jenkins-设置定时任务

    前言 跑自动化用例每次用手工点击 jenkins 出发自动化用例太麻烦了,我们希望能每天固定时间 跑,这样就不用管了,坐等收测试报告结果就行. 一.定时构建语法  * * * * * (五颗星,中间用 ...

  4. 大厂面试官问你META-INF/spring.factories要怎么实现自动扫描、自动装配?

    大厂面试官问你META-INF/spring.factories要怎么实现自动扫描.自动装配?   很多程序员想面试进互联网大厂,但是也有很多人不知道进入大厂需要具备哪些条件,以及面试官会问哪些问题, ...

  5. linux入门系列17--邮件系统之Postfix和Dovecot

    前文演示了通过Samba和NFS实现文件共享,本篇演示使用Postfix和Dovecot在局域网实现电子邮件收发系统. 电子邮件系统是我们日常生活和工作中非常重要的一个网络服务,在windows下收发 ...

  6. CSS+DIV自适应布局

    CSS+DIV自适应布局 1.两列布局(左右两侧,左侧固定宽度200px;右侧自适应占满) 代码如下: <!doctype html> <html> <head> ...

  7. 简单易懂的Servlet路径问题

    关于servlet路径,我看了一下网上别人的博客园,发现都有一个通病,讲的太专业了,又抓不住关键部分,往往看一眼就不想看第二眼.所以我特地准备了初学者所通识的servlet路径问题. 1.标识符 /j ...

  8. safari坑之 video

    博客地址: https://www.seyana.life/post/19 本来是打算给博客左上角的gif做个优化, 把gif换成webm,以video的形式自动播放,能从180k降到50k, 现在浏 ...

  9. 纯C 实现 strpos substr strspilt str_trim

    在C 语言中没有C++ 好用的 spilt 方法 (STL 带的也不怎么好用) #include <stdio.h> #include <string.h> #include ...

  10. 2019.3.14解题报告&补题报告

    A题 题意: 输入r, c,代表r*c的矩阵,接下来一行,是r个数,代表每一行里最大的数:接下来一行,是c个数,代表每一列中的最大数.求所给数据是否冲突. 思路:判断r个数中最大数maxr和c个数中最 ...