regex

python regular expression not matching file contents with re.match and re.MULTILINE flag

吃可爱长大的小学妹 提交于 2021-01-28 19:05:16
问题 I'm reading in a file and storing its contents as a multiline string. Then I loop through some values I get from a django query to run regexes based on the query results values. My regex seems like it should be working, and works if I copy the values returned by the query, but for some reason isn't matching when all the parts are working together that ends like this My code is: with open("/path_to_my_file") as myfile: data=myfile.read() #read saved settings then write/overwrite them into the

Splitting a column in a DataFrame based on multiple possible delimiters

让人想犯罪 __ 提交于 2021-01-28 18:41:53
问题 I have an address column in a dataframe in pandas with 3 types of information namely street, colony and city. There are three values with two possible delimiters - either a ',' or a white-space e.g it can be either Street1,Colony1,City1 or Street1 Colony1 City1 . I need to split this column into three with respective labels 'Street' , 'Colony' and 'City' with the values from this Address column split accordingly. What is the most efficient way to do this as the pandas split function only

Splitting a column in a DataFrame based on multiple possible delimiters

試著忘記壹切 提交于 2021-01-28 18:37:39
问题 I have an address column in a dataframe in pandas with 3 types of information namely street, colony and city. There are three values with two possible delimiters - either a ',' or a white-space e.g it can be either Street1,Colony1,City1 or Street1 Colony1 City1 . I need to split this column into three with respective labels 'Street' , 'Colony' and 'City' with the values from this Address column split accordingly. What is the most efficient way to do this as the pandas split function only

Regular expression (extract key/value pairs)

半腔热情 提交于 2021-01-28 18:33:31
问题 I'm trying to extract a list (match) of key/value pairs from a string. Ex : PATH_1:"/", PATH_2:"/OtherPath", TODAY:"2016-06-27",XYZ :"1234" This should give : Key Value PATH_1 / PATH_2 /OtherPath TODAY 2016-06-27 XYZ 1234 Here is what I have so far as regex : ((?:"[^"]*"|[^:,])*):((?:"[^"]*"|[^:,])*) This is well working except that when I'm adding a path having a '\'. Ex : PATH_1:"c:\", PATH_2:"c:\OtherPath", TODAY:"2016-06-27" I don't know how to instruct to regex expression to jump over

Use Perl to check if a string has only English characters

感情迁移 提交于 2021-01-28 18:18:26
问题 I have a file with submissions like this %TRYYVJT128F93506D3<SEP>SOYKCDV12AB0185D99<SEP>Rainie Yang<SEP>Ai Wo Qing shut up (OT: Shotgun(Aka Shot Gun)) %TRYYVHU128F933CCB3<SEP>SOCCHZY12AB0185CE6<SEP>Tepr<SEP>Achète-moi I am stripping everything but the song name by using this regex. $line =~ s/.*>|([([\/\_\-:"``+=*].*)|(feat.*)|[?¿!¡\.;&\$@%#\\|]//g; I want to make sure that the only strings printed are ones that contain only English characters, so in this case it would the first song title Ai

Python Regex Negative Lookbehind Match without Fixed width

三世轮回 提交于 2021-01-28 17:56:18
问题 I want to find a better way to get my result. I use a regex pattern to match all text of the form (DD+ some text DDDD some other text) if and only if it is not preceded of non-fixed width lookbehind terms. How can I include these terms inside of my REGEX pattern ? aa = pd.DataFrame({"test": ["45 python 00222 sometext", "python white 45 regex 00 222 somewhere", "php noise 45 python 65000 sm", "otherword 45 python 50000 sm"]}) pattern = re.compile("(((\d+)\s?([^\W\d_]+)\s?)?(\d{2}\s?\d{3})\s?(

Ansible regex_search/regex_findall

别等时光非礼了梦想. 提交于 2021-01-28 17:50:17
问题 I'm trying to parse the output of a command that returned a line like this (there's more output, but this is the line that I'm after): Remaining Time: 3 Minutes and 12 Seconds And when there is no time left it returns a line like this: Remaining Time: 0 Seconds I'd like to extract the amount of minutes and seconds, so I can feed it to GNU date -d. First I tried this: - name: determine how much time we have left set_fact: time_left: "{{ cmd_output.stdout | regex_search(time_left_regex, '\\1',

How can I get preg_match_all to match angle brackets?

家住魔仙堡 提交于 2021-01-28 15:46:34
问题 I know it's probably a dumb question, but I am stuck trying to figure out how to make preg_match_all to do what I want... I want to match strings that look like <[someText]> Also, I would like to do this in a lazy fashion, so if a have a string like $myString = '<[someText]> blah blah blah <[someOtherText]> lala [doNotMatchThis] '; I would like to have 2 matches: '<[someText]>' and '<[someOtherText]>' as opposed to a single match '<[someText]> blah blah blah <[someOtherText]>' I am trying to

RegEx for positive number + greater than zero an decimal (0.1)

梦想的初衷 提交于 2021-01-28 15:45:50
问题 I want to validate a field in javascript to have at least 1 and should be positive number or decimal. Examples: 1 1.1 0.1 10.10 My current regex looks like this: var _RegEx = /^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/; 回答1: Simple: /^\+?(\d*[1-9]\d*\.?|\d*\.\d*[1-9]\d*)$/.test(x) Simpler: 0 < parseInt(x, 10) && parseInt(x, 10) < Infinity Simplest: 0 < +x && +x < Infinity && !/[^\d.+]/.test(x) Thanks to Jack, the last one is not so simple anymore. :/ 回答2: ^((0?0?\.([1-9]\d*|0[1-9]\d*))|(([1-9]|0

RegEx for positive number + greater than zero an decimal (0.1)

泄露秘密 提交于 2021-01-28 15:41:20
问题 I want to validate a field in javascript to have at least 1 and should be positive number or decimal. Examples: 1 1.1 0.1 10.10 My current regex looks like this: var _RegEx = /^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/; 回答1: Simple: /^\+?(\d*[1-9]\d*\.?|\d*\.\d*[1-9]\d*)$/.test(x) Simpler: 0 < parseInt(x, 10) && parseInt(x, 10) < Infinity Simplest: 0 < +x && +x < Infinity && !/[^\d.+]/.test(x) Thanks to Jack, the last one is not so simple anymore. :/ 回答2: ^((0?0?\.([1-9]\d*|0[1-9]\d*))|(([1-9]|0