Quote:
Originally Posted by dunhill
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
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)