Fix Python – Python non-greedy regexes

How do I make a python regex like “(.*)” such that, given “a (b) c (d) e” python matches “b” instead of “b) c (d”?
I know that I can use “[^)]” instead of “.”, but I’m looking for a more general solution that keeps my regex a little cleaner. Is there any way to tell python “hey, match this as soon as possible”?
….

Fix Python – Named regular expression group “(?Pregexp)”: what does “P” stand for?

In Python, the (?P…) syntax allows one to refer to the matched string through its name:
>>> import re
>>> match = re.search(‘(?P.*) (?P.*)’, ‘John 123456’)
>>> match.group(‘name’)
‘John’

What does “P” stand for? I could not find any hint in the official documentation.
I would love to get ideas about how to help my studen….

Fix Python – Escaping regex string

I want to use input from a user as a regex pattern for a search over some text. It works, but how I can handle cases where user puts characters that have meaning in regex?
For example, the user wants to search for Word (s): regex engine will take the (s) as a group. I want it to treat it like a string “(s)” . I can run replace on user input and….

Fix Python – In Python, how do I split a string and keep the separators?

Here’s the simplest way to explain this. Here’s what I’m using:
re.split(‘\W’, ‘foo/bar spam\neggs’)
>>> [‘foo’, ‘bar’, ‘spam’, ‘eggs’]

Here’s what I want:
someMethod(‘\W’, ‘foo/bar spam\neggs’)
>>> [‘foo’, ‘/’, ‘bar’, ‘ ‘, ‘spam’, ‘\n’, ‘eggs’]

The reason is that I want to split a string into tokens, manipulate it, then put it back together aga….

Fix Python – Split a string by spaces — preserving quoted substrings — in Python

I have a string which is like this:
this is “a test”

I’m trying to write something in Python to split it up by space while ignoring spaces within quotes. The result I’m looking for is:
[‘this’, ‘is’, ‘a test’]

PS. I know you are going to ask “what happens if there are quotes within the quotes, well, in my application, that will never happen.
….