python-regex

Regex in Python: Separate words from numbers JUST when not in list

依然范特西╮ 提交于 2021-02-19 05:40:30
问题 I have a list containing some substitutions which I need to keep. For instance, the substitution list: ['1st','2nd','10th','100th','1st nation','xlr8','5pin','h20'] . In general, strings containing alphanumeric characters need to split numbers and letters as follows: text= re.sub(r'(?<=\d)(?=[^\d\s])|(?<=[^\d\s])(?=\d)',' ',text,0,re.IGNORECASE) The previous regex pattern is separating successfully all numbers from characters by adding space between in the following: Original Regex ABC10 DEF

grab required field values from the paragraph block using regex in python

假装没事ソ 提交于 2020-12-15 04:57:30
问题 I've a text file, from that I have extracted these two paragraph block. The text example is give below. Text Example: EXONERAR, com validade a contar de 19 de agosto de 2020 , DE- NILSON DE BRITO LIMA , ID FUNCIONAL Nº 2100423-4 , do cargo em comissão de Coordenador , símbolo DAS-8 , da Coordenadoria de Gestão Centralizada de Serviços, da Superintendência de Gestão Centralizada, da Subsecretaria de Logística , da Secretaria de Estado de Planejamento e Gestão . Processo nº SEI- 120001/010643

Regex: Add space after a number when followed by letter

試著忘記壹切 提交于 2020-02-05 06:16:25
问题 Following a set of numbers I would like to add a space to the string. For instance, the following strings should add a space after a number: Before After "0ABCD TECHNOLOGIES SERVICES" "0 ABCD TECHNOLOGIES SERVICES" "ABCD0 TECHNOLOGIES SERVICES" "ABCD 0 TECHNOLOGIES SERVICES" "ABCD 0TECHNOLOGIES SERVICES" "ABCD 0 TECHNOLOGIES SERVICES" "ABCD TECHNOLOGIES0 SERVICES" "ABCD TECHNOLOGIES 0 SERVICES" "ABCD TECHNOLOGIES 0SERVICES" "ABCD TECHNOLOGIES 0 SERVICES" "ABCD TECHNOLOGIES SERVICES0" "ABCD

python parse specific text in multiple line

旧时模样 提交于 2019-12-24 19:55:58
问题 I have a text file contain a sample data like this: [|] Name: Foo Bar [|] Username: xx@example.org [|] NickName: Boox AA [|] Logo Box: Unique-w.jpg [|] Country: EU ========================================= [|] Name: Doo Mar [|] Username: cc@example.net [|] Logo Box: Unique-w.jpg [|] Country: EU [|] Mob: 00000000 I need to get Username and Logo Box values I tried using for loop to get 2 lines each time and analyze it but it does not work as expected. def read_file_lines(file_path): with open

how to check if a string fullfil with multiple regex and capture that portion that match?

五迷三道 提交于 2019-12-20 03:55:13
问题 What I want I'm working with a django form and it takes a password input. I need to pass the input value for multiple regexes, which will test if: at least one character is a lowecase at least one character is a uppercase at least one character is a number at least one character is a especial character (symbol) 8 characters minimum And I would like to know which of these conditions were fulfilled and which were not. What I've done def clean_password(self): password = self.cleaned_data.get(

Whatsapp chat log parsing with regex

╄→гoц情女王★ 提交于 2019-12-11 19:28:35
问题 I'm trying to parse a whatsapp chat log using regex. I have a solution that works for most cases but I'm looking to improve it but don't know how to since I am quite new to regex. The chat.txt file looks like this: [06.12.16, 16:46:19] Person One: Wow thats amazing [06.12.16, 16:47:13] Person Two: Good morning and this goes over multiple lines as it is a very long message [06.12.16, 16:47:22] Person Two: :: While my solution so far would parse most of these messages correctly, however I have

re.sub(“.*”, “, ”(replacement)“, ”text") doubles replacement on Python 3.7

对着背影说爱祢 提交于 2019-12-05 17:49:22
问题 On Python 3.7 (tested on Windows 64 bits), the replacement of a string using the RegEx .* gives the input string repeated twice! On Python 3.7.2: >>> import re >>> re.sub(".*", "(replacement)", "sample text") '(replacement)(replacement)' On Python 3.6.4: >>> import re >>> re.sub(".*", "(replacement)", "sample text") '(replacement)' On Python 2.7.5 (32 bits): >>> import re >>> re.sub(".*", "(replacement)", "sample text") '(replacement)' What is wrong? How to fix that? 回答1: This is not a bug,

re.sub(“.*”, “, ”(replacement)“, ”text\") doubles replacement on Python 3.7

浪子不回头ぞ 提交于 2019-12-04 02:25:50
On Python 3.7 (tested on Windows 64 bits), the replacement of a string using the RegEx .* gives the input string repeated twice! On Python 3.7.2: >>> import re >>> re.sub(".*", "(replacement)", "sample text") '(replacement)(replacement)' On Python 3.6.4: >>> import re >>> re.sub(".*", "(replacement)", "sample text") '(replacement)' On Python 2.7.5 (32 bits): >>> import re >>> re.sub(".*", "(replacement)", "sample text") '(replacement)' What is wrong? How to fix that? This is not a bug, but a bug fix in Python 3.7 from the commit fbb490fd2f38bd817d99c20c05121ad0168a38ee . In regex, a non-zero