How do I make a regular expression that matches the following in Python?
Question: Assuming I have many strings that are like this:

    
    
    <a id="1.1">
    <a id="1.1.1">
    <a id="1.1.2">
    <a id="1.1.3">
    <a id="1.2">
    <a id="1.2.1">
    

I want to make a regular expression that catches only the ones with "#.#", so
I am trying to match it such that it ends with a double quote, but I am
getting no matches.

    
    
    re.compile("[1-9].[1-9]\"")
    

The resulting output I expect is a list containing:

    
    
      <a id="1.1">
      <a id="1.2">
    

What am I doing wrong? (Please suggest if there is a better way to match than
the method I am using.)


Answer: Put double quotes on both sides: `r'"\d\.\d"'`.

For example,

    
    
    In [109]: import re
    
    In [110]: text = '''<a id="1.1">
    <a id="1.1.1">
    <a id="1.1.2">
    <a id="1.1.3">
    <a id="1.2">
    <a id="1.2.1">'''.splitlines()
    
    In [111]: [line for line in text if re.search(r'"\d\.\d"', line)]
    Out[111]: ['<a id="1.1">', '<a id="1.2">']
    

