RegEx to extract all matches from string using RegExp.exec

I’m trying to parse the following kind of string: [key:”val” key2:”val2″] where there are arbitrary key:”val” pairs inside. I want to grab the key name and the value. For those curious I’m trying to parse the database format of task warrior. Here is my test string: [description:”aoeu” uuid:”123sth”] which is meant to highlight that anything … Read more

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

In Python, the (?P<group_name>…) syntax allows one to refer to the matched string through its name: >>> import re >>> match = re.search(‘(?P<name>.*) (?P<phone>.*)’, ‘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 … Read more

What is a non-capturing group in regular expressions?

How are non-capturing groups, i.e., (?:), used in regular expressions and what are they good for? 1 18 Let me try to explain this with an example. Consider the following text: http://stackoverflow.com/ https://stackoverflow.com/questions/tagged/regex Now, if I apply the regex below over it… (https?|ftp)://([^/\r\n]+)(/[^\r\n]*)? … I would get the following result: Match “http://stackoverflow.com/” Group 1: “http” … Read more