[英]Regex: take everything after match
I have many strings in a dataframe, an example being: 我在数据框中有很多字符串,一个例子是:
adrianos ristorante 2930 beverly glen circle los angeles 310475 9807 italian
I want to take all words/characters after the phone number. 我想在电话号码后输入所有的单词/字符。 I have the regex for getting the phone number and space after(
([0-9]{6}\\s[0-9]{4})\\s
). 我有用于获取电话号码和(
([0-9]{6}\\s[0-9]{4})\\s
)之后的空格的正则表达式。 What I want is all characters after this. 我想要的是这之后的所有角色。 In this case it's
italian
but it could be something like asian fusion
or indian and thai
. 在这种情况下,它是
italian
但可能是asian fusion
或indian and thai
这样的东西。
In Pandas, you may use 在熊猫中,您可以使用
[0-9]{6}\s[0-9]{4}\s+(.+)
^^^^^
The code will look like 代码看起来像
df['col'].str.extract('[0-9]{6}\s[0-9]{4}\s+(.+)')
Note you should wrap the part you need to extract with a capturing group, (...)
. 请注意,应使用捕获组
(...)
包装需要提取的部分。 See Pandas reference : 参见熊猫参考 :
pat : string
pat : 字符串
Regular expression pattern with capturing groups
具有捕获组的正则表达式模式
You can do (in Notepad++): 您可以执行(在Notepad ++中):
Find What: (. )([0-9]{6}\\s[0-9]{4})\\s(. ) Replace with: $3 查找内容:(。 )([0-9] {6} \\ s [0-9] {4})\\ s(。 )替换为:$ 3
$3 gives the 3rd argument which is everything after your matching phone number. $ 3给出第三个参数,它是匹配电话号码之后的所有内容。
Using this regular expression: /([0-9]{6}\\s[0-9]{4})\\s(.*$)/m
使用以下正则表达式:/([
/([0-9]{6}\\s[0-9]{4})\\s(.*$)/m
You will have anything after the phone number, until the end of the line (you can omit the m
flag if you want to get everything until the end of the string), in the second capture group. 在第二个捕获组中,您将在电话号码之后直到行尾为止有任何内容(如果要在字符串末尾之前得到所有内容,则可以省略
m
标志)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.