Regex in Python to find Rows in Table
<p>i`m using python to automate some test, and at one point i find a table with rows, but this rows are of two different clases:</p>

<p>You have class name "gris-claro-tr" and "gris-oscuro-tr".</p>

<p>I need to iterate the whole table, finding the text of every row. Until now, i have:</p>

<pre><code>        for row in driver.find_elements_by_class_name("gris-claro-tr"):    
            cell = row.find_elements_by_tag_name("td")[1]
            print (cell.text)
</code></pre>

<p>But of course, only works for the rows with that class. I have to do the same thing for "gris-oscuro-tr". However, if i could find a regex that could find both row`s class, i would get the text of every row in that table, no matter if it is "gris-claro-td" or "gris-oscuro-td". </p>

<p>The question is: how can i make that regex? </p>

<p>Is it something like "gris-"+"*" ?</p>

<p>Thank you very much!</p>

<p>You can approach it with a <em>CSS selector</em>:</p>

<pre><code>driver.find_elements_by_css_selector(".gris-claro-tr,.gris-oscuro-tr")
</code></pre>

<p><code>,</code> here means "or", dot defines a class name selector.</p>

<hr>

<p>Or, you can apply the partial matches as well, a little bit less explicit though:</p>

<pre><code>driver.find_elements_by_css_selector("[class^=gris][class$=tr]")
</code></pre>

<p>where <code>^=</code> means "starts with", <code>$=</code> means "ends with".</p>

python regex webdriver