Quickie - Regexp for a string not at the beginning of the line
Asen Bozhilov
asen.bozhilov at gmail.com
Fri Oct 26 06:46:55 EDT 2012
Rivka Miller wrote:
> I am looking for a regexp for a string not at the beginning of the
> line.
>
> For example, I want to find $hello$ that does not occur at the
> beginning of the string, ie all $hello$ that exclude ^$hello$.
The begging of the string is zero width character. So you could use
negative lookahead (?!^).
Then the regular expression looks like:
/(?!^)\$hello\$/g
var str = '$hello$ should not be selected but',
str1 = 'not hello but all of the $hello$ and $hello$ ... $hello$
each one ';
str.match(/(?!^)\$hello\$/g); //null
str1.match(/(?!^)\$hello\$/g); //["$hello$", "$hello$", "$hello$"]
More information about the Python-list
mailing list