Quickie - Regexp for a string not at the beginning of the line

Janis Papanagnou janis_papanagnou at hotmail.com
Thu Oct 25 17:01:47 EDT 2012


On 25.10.2012 22:53, Rivka Miller wrote:
> Hello Programmers,
> 
> 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$.

   .hello

The dot represents any character. But for specific strings that
needs adjustments (e.g. looking for hh not at the beginning of a
line would require something like ^[^h]+hh - ah, well, you wrote
something similar below).

Janis

> 
> In addition, if you have a more difficult problem along the same
> lines, I would appreciate it. For a single character, eg < not at the
> beginning of the line, it is easier, ie
> 
> ^[^<]+<
> 
> but I cant use the same method for more than one character string as
> permutation is present and probably for more than one occurrence,
> greedy or non-greedy version of [^<]+ would pick first or last but not
> the middle ones, unless I break the line as I go and use the non-
> greedy version of +. I do have the non-greedy version available, but
> what if I didnt?
> 
> If you cannot solve the problem completely, just give me a quick
> solution with the first non beginning of the line and I will go from
> there as I need it in a hurry.
> 
> Thanks
> 
> 




More information about the Python-list mailing list