View Single Post
Old 03-28-2026, 08:58 PM   #4
lomkiri
Groupie
lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.
 
lomkiri's Avatar
 
Posts: 191
Karma: 1537710
Join Date: Jul 2021
Device: N/A
Quote:
Originally Posted by dunhill View Post
You could try this:
`class="[^"]*(^|\s)bc(\s|$)[^"]*"`

`(^|\s)`: Ensures that your class name is preceded by a quote or a space.

`(\s|$)`: Ensures that it is followed by a space or a closing quote.
I don't agree with you:
(^|\s)bc : Ensures that bc is at the beginning of the line (which never happens since you put class="[^"]* before this expression) or after \s

bc(\s|$) : same problem, ensures that bc is at the EoL (never happens) or before \s

So it would select class="ab bc de" but neither class="ab bc" nor class="bc cd ef"

A working regexp would be :
class="[^"]*?\s*\Kbc(?=[\s"])
it will select only bc in the class (only the first one if there is several of it)
\K asks for resetting the chain (forget what is before \K)
(?=[\s"]) is a lookahead, it selects bc only if it's followed by \s or "

Quote:
Originally Posted by dunhill View Post
If, on the other hand, you want to see all the classes that define something related to the border (assuming they all start with `b`), you can use:

`class="[^"]*(^|\s)b[a-z]*(\s|$)[^"]*"`
There is also _ and - to be considered.
In that case, this one does the job (finds only the 1st one):
class="[^"]*?\s*\Kbc[\w-]*(?=[\s"])

or, if you want bc and up to 3 more char (e.g. bc, bcd, bcdef, bc-d, bc_de)
class="[^"]*?\s*\Kbc[\w-]{0,3}(?=[\s"])
(change {0,3} for whatever number you need)

Last edited by lomkiri; 03-28-2026 at 09:11 PM.
lomkiri is offline   Reply With Quote