FAQ Database Discussion Community


Non-greedy mode in re.search() does not match to end of string

python,regex,non-greedy
I'm trying to parse values of a cookie like this: import re m = re.search("(.*?)=(.*?); path=(.*?); domain=(.*?)", "name=value1; path=/; domain=my.domain.com") print (m.group(0)) Result I get is like this: name=value1; path=/; domain= My question is: why does it not match at the last non-greedy position? Expected result would be: name=value1; path=/;...

“Optional” end of line $ literal (non greedy)

regex,non-greedy,end-of-line
I would like to make the "end of line" character ($) "optional" (or non-greedy). Meaning, I want to capture a certain pattern at the end of the line, or none. This is the regex I've built: (.+\s*)\s*(?:(\(\s*[xX\*]\s*\d+\s*\))|$) I would like to capture things like Incompatible device (x10) ; Boot sequence...

Regex searching for time doesn't want to be non-greedy

regex,quantifiers,non-greedy,spiceworks
I'm trying to run a regex in Spiceworks to parse through email headers to select the first instance of time for ticket assignment purposes. The regex itself works, but it picks up all instances of time rather than just one. Here's the regex: \.*(0[1]|1[3-7]):\d\d:\d\d I've tried to make in non-greedy...

Java, poor regex performance with lazy expressions

java,regex,performance,non-greedy
The code is actually in Scala (Spark/Scala) but the library scala.util.matching.Regex, as per the documentation, delegates to java.util.regex. The code, essentially, reads a bunch of regex from a config file and then matches them against logs fed to the Spark/Scala app. Everything worked fine until I added a regex to...

Non-Greedy regex acts greedy based on the position of atoms in regex

regex,tcl,non-greedy
I came across one situation where I wanted to use non-greedy atom .*? in the regex pattern. set input "Device ID: HOST1 Interface: GigabitEthernet0/1, Port ID (outgoing port): GigabitEthernet2/43 Device ID: HOST2 Entry address(es): Interface: GigabitEthernet0/2, Port ID (outgoing port): GigabitEthernet2/43 " puts "======== Non-Greedy regex starting with some other...