Oniguruma question

  • Thread starter Kenneth McDonald
  • Start date
K

Kenneth McDonald

For those adventurous souls who are already using Oniguruma...

With the following Oniguruma re:

print "aabb".index(/.+?(?<!a)/)
print "\n"

My reasoning tells me I should be getting 3, but I'm getting 0.
Basically, the .+ should force the re 'cursor' past at least the first
a; after that, the negative lookback should force it past the first b.
Could someone explain where I'm misunderstanding?

Thanks,
Ken
 
R

Robert Klemme

I'm writing a library to make re's easier to use :) This is in the
test suite.

Thanks for the feedback, that comes as a real surprise to me. So maybe
I'll try /..+?/

This one won't match after "aa". Instead it will match "aa". I do not
know what you intend to match so I cannot really comment. This is
clearly a toy example, isn't it? There are multiple ways to match "bb"
in "aabb" and it is completely unclear to me what you are after.

Your original RX literally translated means "match anything which is not
preceded by a" which is especially true for every character at the
beginning of a string.

Btw, I can recommend "Mastering Regular Expressions" - it is a really
good book on the matter.

Kind regards

robert
 
K

Kenneth McDonald

It was part of a unit testing suite. I did figure out where I was
going wrong, a silly mistake on my part which I should've been past
years ago. Thanks for the help.

Ken
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,279
Messages
2,571,387
Members
48,090
Latest member
marky2025

Latest Threads

Top