Page 1 of 1

Welche Regex-Funktion könnte ich verwenden, um die Antworten zu finden?

Posted: 30 Dec 2024, 20:06
by Guest
Hier sind die String-Typen, die ich in Python habe:

Code: Select all

$\textbf{(A) }4\qquad\textbf{(B) }6\qquad\textbf{(C) }7\qquad\textbf{(D) }10\qquad\textbf{(E) }11$
$\textbf{(A)}\ 2S + 3\qquad \textbf{(B)}\ 3S + 2\qquad \textbf{(C)}\ 3S + 6 \qquad\textbf{(D)}\ 2S + 6 \qquad \textbf{(E)}\ 2S + 12$
$\textbf{(A) }50 \qquad \textbf{(B) }52  \qquad \textbf{(C) }54 \qquad \textbf{(D) }56 \qquad \textbf{(E) }58$
$\text{(A) }4^4 5^5 6^6 \qquad \text{(B) }4^4 5^6 6^5 \qquad \text{(C) }4^5 5^4 6^6 \qquad \text{(D) }4^6 5^4 6^5 \qquad \text{(E) }4^6 5^5 6^4$
$\mathrm{(A) \ } \frac{1}{4}\qquad \mathrm{(B) \ } \frac13\qquad \mathrm{(C) \ } \frac38\qquad \mathrm{(D) \ } \frac25\qquad \mathrm{(E) \ } \frac12$
Ich möchte die Antworten aus diesen Zeilen extrahieren, also den Text nach (A), (B), (C), (D) und (E). Für die erste Zeile möchte ich beispielsweise Folgendes erhalten:

Code: Select all

[4, 6, 7, 10, 11]
Für die letzte Zeile:

Code: Select all

[\frac{1}{4}, \frac13, \frac38, \frac25, \frac12]
Es gibt viele Variationen in den Zeilen und ich kann keinen regulären Ausdruck finden, der diese Aufgabe erfüllen kann. Für jede Hilfe wäre ich dankbar.
Ich habe versucht, so etwas zu verwenden wie:

Code: Select all

line = "$\textbf{(A) }4\qquad\textbf{(B) }6\qquad\textbf{(C) }7\qquad\textbf{(D) }10\qquad\textbf{(E) }11$"
A = re.findall(r"(?