Skip to content

Tag: regex

grab specific field value from the string using regex

I’ve a text file, from that I have extracted these two paragraph block. The text example is given below: Text Example: NOMEAR ISABELLE FERREIRA ZARONI, ID FUNCIONAL Nº 5100796-7, para exercer, com validade a contar de 16 de novembro de 2020, o cargo em comissão de Assessor, símbolo DAS-7, da Sub- secret…

How to extract multiple strings using Regex?

I have a column in a df contains the following values: I would like to use regex to extract the KEY into a new column without the actual “KEY_”. For those sentences have more than 1 KEY, they should be joined with a comma. The output should be as below: I tried with this code but it is not working…

Question on regex not performing as expected

I am trying to change the suffixes of companies such that they are all in a common pattern such as Limited, Limiteed all to LTD. Here is my code: I’m trying ‘ABC CORPORATN’ and it’s not converting it to CORP. I can’t see what the issue is. Any help would be great. Edit: I have tr…

Python using Regular Expression to convert a string

I want to convert the duration variable from YouTube Data api? PT1M6S –> 1:06 PT38S –> 0:38 PT58M4 –> 58:04 Here is my codes: p[‘duration’] is the value from json data Is there a simple way to do in one regex statement? Thanks! Answer An alternative to using a regex is u…

How to substitute only second occurrence of re.search() group

I need to replace part of the string value with extra zeroes if it needs. T-46-5-В,Г,6-В,Г —> T-46-005-В,Г,006-В,Г or T-46-55-В,Г,56-В,Г —> T-46-055-В,Г,066-В,Г, for example. I have Regex pattern ^D-d{1,2}-([d,]+)-[а-яА-я,]+,([d,]+)-[а-яА-я,]+$ that retrieves 2 separate groups of the string,…