Skip to content

Tag: regex

Add a space after a word if it’s at the beginning of a string or if it’s after one or more spaces, and at the same time it must be at end or before n

How to obtain this outputs from those inputs? Note that for examples 4, 5, 6 and 7 the regex should not make any changes, since after the word there is already a space placed, or because in the case of “uno”, the word “un” is not at the end of the sentence, or in the case of “treinta yun” the

Regex to split text based on a sentence pattern

I have a text that looks something like: ‘19:54:12 From X to Y: some text after 21:08:15 From A to B:another text’ I want to split the text based on the 19:54:12 From X to Y: sentence pattern. Ideally the result would look something like this [‘19:54:12 From X to Y:’, ‘ some text after’, ‘21:08:15 From A to B:’,

capture pattern_X repeatedly, then capture pattern_Y once, then repeat until EOS

[update:] Accepted answer suggests, this can not be done with the python re library in one step. If you know otherwise, please comment. I’m reverse-engineering a massive ETL pipeline, I’d like to extract the full data lineage from stored procedures and views. I’m struggling with the following regexp. TLDR: I’d like to capture from a string like where a,b,e,f,h match

Regex Match on String (DOI)

Hi I’m struggling to understand why my Regex isn’t working. I have URL’s that have DOI’s on them like so: And I’m using for example this Regex, but it always returns empty? Where have I gone wrong? Answer It looks like you come from another programming language that has the notion of regex literals that are delimited with forward slashes

Regex returns empty string despite working on regex101 python [closed]

Closed. This question needs debugging details. It is not currently accepting answers. Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question. Closed 29 days ago. Improve this question I’m trying to do a regex on this string And it must return

Python Regex for Searching pattern in text file

Tags in Sample.txt: <ServiceRQ>want everything between…</ServiceRQ> <ServiceRQ xmlns:xsi=”>want everything between</ServiceRQ> .. Please can someone help me to get the regex? To extract the expected output from a text file. I want to create a regex to find the above tags. This is what is have tried”<(.*?)RQ(.*?)>(.*?)</(.*?)RQ>”, line) but not working properly. I want to make a search based on

Python convert all-caps into title case without messing with camel case

I’m using python3 and would like to turn strings that contain all caps words (separately or inside a word) into title case (first letter capitalized). I do not want to disrupt one-off capital letters in the middle of a word (camel case), but if there are repeated capitalized letters, I want to keep only the first one capitalized. Here’s the