-1

Hi I have the following string:

t = '<td align="right" class="ofGridLinesTop" headers="amount" sortvalue="2633.33" valign="top">\n\t\t\t\t\t  \n\t\t\t\t\t  \n\t\t\t\t\t  \n\t\t\t\t\t\t$2,633.33\n\t\t\t\t\t  \n\t\t\t\t\t  \n\t\t\t\t\t</td>'

I know that the following Regex sequence properly identifies the part of the string I want (sortvalue="2633.33")

\bsortvalue=.\b\d+.\d+.

Yet when I use the following statement:

Amt = re.findall('\bsortvalue=.\b\d+.\d+.',t)

I come up empty. Any idea why?

Andrii Abramov
  • 10,019
  • 9
  • 74
  • 96
scharlesc
  • 11
  • 1

1 Answers1

1

Use this:

Amt = re.findall('\\bsortvalue=.\\b\d+.\d+.',t)

or this:

Amt = re.findall(r'\bsortvalue=.\b\d+.\d+.',t)

See also this question

logi-kal
  • 7,107
  • 6
  • 31
  • 43
  • Correct answer but should explain; you're not escaping the backslash in `\b` etc so you're actually substituting those escape codes instead of what you intended (i.e. \b is backspace). To fix you can either escape the backslash i.e. `\\b` or create a raw string by prefixing the regex with `r` as in Horcrux' 2nd example which is essentially a string literal and as such ignores the escape characters. – Dillanm May 23 '17 at 15:05