Pergunta

I'm working on this regex, and it's not functioning as I expected. Here is my regex thus far -- .{12}(?=.)$|(^.{1,12}$)

The first half, .{12}(?=.)$ is where I'm stuck. I'm trying to match the first twelve of the last thirteen characters from an input string.

Examples:
1234567890123 --> 123456789012
123456789012345 --> 345678901234
12345678901234567890 --> 890123456789

It seems like the lookahead is failing for me. Using the demo of something like q(?=w) correctly matches a q followed by a w, but I can't get it to work in my specific instance.

Thanks!

Foi útil?

Solução

The look-ahead is zero-width so (?=.)$ is a contradiction

.{12}(?=.$)|^.{1,12}$
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top