(Feb-06-2017, 08:33 PM)DBS Wrote: Hello,
I'm trying to formulate a regex search to see if this exact string, ''op_single_selector" exists in this line of text:
-> [!div class="op_single_selector"]
This is what I have now that's not working:
selector_string = False single_selector_regex_search_string = re.compile(r"[\+-]>\s\[op_single_selector\]") if single_selector_regex_search_string.search(file_information.patch): selector_string = True
Are you trying to parse HTML with regex?
You can just use the
in
operator.if target in search_string:However if its HTML, then something like BeautifulSoup is better.
from bs4 import BeautifulSoup data = ''' <html> <body> <div class="op_single_selector"> content </div> </body> </html> ''' soup = BeautifulSoup(data, 'html.parser') search = soup.find('div', class_='op_single_selector') if search: #there is a class op_single_selectoror similar
print('op_single_selector' in soup.div['class'])
Output:True
Recommended Tutorials: