in reply to Applying a regex to part of a string

Roger's solution is clearly better than what i'm about to suggest, but you can also limit the positions with your regex.. in this case something like /^.{10,20}hello world/si since, for 'hello world' to be in the first 30 characters it must not have more than 20 chars (i might have counted wrong by one) preceeding it, but there must be at least 10 before it.

Replies are listed 'Best First'.
Re^2: Applying a regex to part of a string
by holdyourhorses (Monk) on Aug 18, 2005 at 14:08 UTC

    I like it.

    This one seems to have the least side effects, i.e. I don't have to extract anything before, and the regex will take care of failing when the pattern is not in the wanted position.

    So simple, but I did not think about it!

    Thanks.