regex

Extract regex matches, and not groups, in data frames rows in Python

∥☆過路亽.° 提交于 2021-01-29 01:44:16
问题 I am a novice in coding and I generally use R for this (stringr) but I started to learn also Python's syntax. I have a data frame with one column generated from an imported excel file. The values in this column contain both capital and smallcase characters, symbols and numbers. I would like to generate a second column in the data frame containing only some of these words included in the first column according to a regex pattern. df = pd.DataFrame(["THIS IS A TEST 123123. s.m.", "THIS IS A

Convert a multi-line string into a javascript object

我的未来我决定 提交于 2021-01-29 01:42:06
问题 I've my raw data that looks like this: Last Name, First Name (Details-Details) #ID Last Name, First Name (Details-Details) #ID Last Name, First Name (Details-Details) #ID Last Name, First Name (Details-Details) #ID Last Name, First Name (Details-Details) #ID Last Name, First Name (Details-Details) #ID x1000 I'd like to convert into a loopable object with keys and values something like: var d = { "FirstName LastName": "#ID"; "FirstName LastName": "#ID"; "FirstName LastName": "#ID"; "FirstName

Extract regex matches, and not groups, in data frames rows in Python

北战南征 提交于 2021-01-29 01:41:51
问题 I am a novice in coding and I generally use R for this (stringr) but I started to learn also Python's syntax. I have a data frame with one column generated from an imported excel file. The values in this column contain both capital and smallcase characters, symbols and numbers. I would like to generate a second column in the data frame containing only some of these words included in the first column according to a regex pattern. df = pd.DataFrame(["THIS IS A TEST 123123. s.m.", "THIS IS A

Convert a multi-line string into a javascript object

独自空忆成欢 提交于 2021-01-29 01:38:13
问题 I've my raw data that looks like this: Last Name, First Name (Details-Details) #ID Last Name, First Name (Details-Details) #ID Last Name, First Name (Details-Details) #ID Last Name, First Name (Details-Details) #ID Last Name, First Name (Details-Details) #ID Last Name, First Name (Details-Details) #ID x1000 I'd like to convert into a loopable object with keys and values something like: var d = { "FirstName LastName": "#ID"; "FirstName LastName": "#ID"; "FirstName LastName": "#ID"; "FirstName

Is it possible to rename PascalCase1.wav to kebab-case-1.wav with a single perl regex?

时间秒杀一切 提交于 2021-01-29 00:45:00
问题 Here is a sample of my data: SomePascalCase.wav ThingsThat1.wav Are.wav Here.wav Here is the result I'm looking for: some-pascal-case.wav things-that-1.wav are.wav here.wav Here is what I used: for f in *.wav; do mv "$f" $( echo "$f" | perl -pe 's/([A-Z])([a-z]+)(?=[0-9A-Z])/\L\1\2-/g' | perl -pe 's/([A-Z])([a-z]+)(?=.wav)/\L\1\2/g' ) done Is it possible to consolidate the two regular expressions I used into a single one? 回答1: You wouldn't really use a regex substitution here. You would use

Is it possible to rename PascalCase1.wav to kebab-case-1.wav with a single perl regex?

我的梦境 提交于 2021-01-29 00:40:55
问题 Here is a sample of my data: SomePascalCase.wav ThingsThat1.wav Are.wav Here.wav Here is the result I'm looking for: some-pascal-case.wav things-that-1.wav are.wav here.wav Here is what I used: for f in *.wav; do mv "$f" $( echo "$f" | perl -pe 's/([A-Z])([a-z]+)(?=[0-9A-Z])/\L\1\2-/g' | perl -pe 's/([A-Z])([a-z]+)(?=.wav)/\L\1\2/g' ) done Is it possible to consolidate the two regular expressions I used into a single one? 回答1: You wouldn't really use a regex substitution here. You would use

Redundant If Statement and Regex

纵然是瞬间 提交于 2021-01-29 00:29:14
问题 The following code is clearly redundant, but in my experience I use this pattern fairly often. Is there some better way to do this in python? if re.search("at (\d{1,2}):\d{2}", p): a=re.search("at (\d{1,2}):\d{2}",p).group(1) 回答1: Yes, it is redundant; you should assign the result of search() to a variable instead of calling it twice: m = re.search("at (\d{1,2}):\d{2}", p) if m: a = m.group(1) or maybe a = m.group(1) if m else some_default_value Also, if you're going to be using this pattern

Redundant If Statement and Regex

杀马特。学长 韩版系。学妹 提交于 2021-01-29 00:21:22
问题 The following code is clearly redundant, but in my experience I use this pattern fairly often. Is there some better way to do this in python? if re.search("at (\d{1,2}):\d{2}", p): a=re.search("at (\d{1,2}):\d{2}",p).group(1) 回答1: Yes, it is redundant; you should assign the result of search() to a variable instead of calling it twice: m = re.search("at (\d{1,2}):\d{2}", p) if m: a = m.group(1) or maybe a = m.group(1) if m else some_default_value Also, if you're going to be using this pattern

Redundant If Statement and Regex

こ雲淡風輕ζ 提交于 2021-01-29 00:17:54
问题 The following code is clearly redundant, but in my experience I use this pattern fairly often. Is there some better way to do this in python? if re.search("at (\d{1,2}):\d{2}", p): a=re.search("at (\d{1,2}):\d{2}",p).group(1) 回答1: Yes, it is redundant; you should assign the result of search() to a variable instead of calling it twice: m = re.search("at (\d{1,2}):\d{2}", p) if m: a = m.group(1) or maybe a = m.group(1) if m else some_default_value Also, if you're going to be using this pattern

In delimited string replace substring between the delimiters only if the substring matches replacement value

谁说胖子不能爱 提交于 2021-01-29 00:12:28
问题 I need to in a delimited string, replace substring between the delimiters only if the substring matches the replacement value Using this in Google sheets The matching var ifind = ["AA", "CaaL"]; var ireplace = ["zz", "Bob"]; zz replaces AA Bob replaces CaaL I have | Id | Segment | |----|--------------------| | 1 | AAA AA|AA|CaaL AA | | 2 | AAA-AA|AA|CaaL | | 3 | AAA, AA|AA|AA | | 4 | AA | | 5 | AA AA | | 6 | AA, AA | | 7 | | | 8 | CaaL | | 9 | AA | I need | Id | Segment | |----|--------------