Skip to content

Tag: regex

regular expression match starting clause with end

I want to be able to capture the value of an HTML attribute with a python regexp. currently I use My problem is that I want the regular expression to “remember” whether the attribute started with a single or a double quote. I found the bug in my current approach with the following attribute my reg…

Regular expression in Python won’t match end of a string

I’m just learning Python, and I can’t seem to figure out regular expressions. I want this code to print ‘yes’, but it obstinately prints ‘no’. I’ve also tried each of the following: Plus countless other variations. I’ve been searching for quite a while, but can&…

Using a RegEx to match IP addresses

I’m trying to make a test for checking whether a sys.argv input matches the RegEx for an IP address… As a simple test, I have the following… However when I pass random values into it, it returns “Acceptable IP address” in most cases, except when I have an “address” th…

Check for camel case in Python

I would like to check if a string is a camel case or not (boolean). I am inclined to use a regex but any other elegant solution would work. I wrote a simple regex Would this be correct? Or am I missing something? Edit I would like to capture names in a collection of text documents of the format Edit2

Get the string within brackets in Python

I have a sample string <alpha.Customer[cus_Y4o9qMEZAugtnW] active_card=<alpha.AlphaObject[card] …>, created=1324336085, description=’Customer for My Test App’, livemode=False> I only want the value cus_Y4o9qMEZAugtnW and NOT card (which is inside another []) How could I do it in …

Regular expression to find any number in a string

What’s the notation for any number in re? Like if I’m searching a string for any number, positive or negative. I’ve been using d+ but that can’t find 0 or -1 Answer Searching for positive, negative, and/or decimals, you could use [+-]?d+(?:.d+)? This isn’t very smart about leadin…