I would like to write a regex for searching for the existence of some words, but their order of appearance doesn’t matter.
I’m attempting to string match 5-digit coupon codes spread throughout a HTML web page. For example, 53232
, 21032
, 40021
etc… I can handle the simpler case of any string of 5 digits with [0-9]{5}
, though this also matches 6, 7, 8… n digit numbers. Can someone please suggest how I would modify this regular expression to match only 5 digit numbers?
I have a string in Python, say The quick @red fox jumps over the @lame brown dog.
I’m parsing strings that could have any number of quoted strings inside them (I’m parsing code, and trying to avoid PLY). I want to find out if a substring is quoted, and I have the substrings index. My initial thought was to use re to find all the matches and then figure out the range of indexes they represent.
I have strings that contain a number somewhere in them and I’m trying to replace this number with their word notation (ie. 3 -> three). I have a function that does this. The problem now is finding the number inside the string, while keeping the rest of the string intact. For this, I opted to use the re.sub
function, which can accept a “callable”. However, the object passed to it is the internal _sre.SRE_Match
and I’m not sure how to handle it. My function accepts a number or its string representation.
Is there a way that I can find out how many matches of a regex are in a string in Python? For example, if I have the string "It actually happened when it acted out of turn."
I have the output of a command in tabular form. I’m parsing this output from a result file and storing it in a string. Each element in one row is separated by one or more whitespace characters, thus I’m using regular expressions to match 1 or more spaces and split it. However, a space is being inserted between every element:
I’m reading a response from a source which is an journal or an essay and I have the html response as a string like:
In the snippet below, the non-capturing group "(?:aaa)"
should be ignored in the matching result,
I am running through lines in a text file using a python script. I want to search for an img tag within the text document…