0

I want to match the answer blocks (the bold ones).

A) I ve II B) III ve IV C) III ve IV D) III ve IV E) III ve IV

So far i wrote this.

(?:[A|B|C|D|E]\) )

It match this

A) I ve II B) III ve IV C) III ve IV D) III ve IV E) III ve IV

But when i append (.*) to it it matches

A) I ve II B) III ve IV C) III ve IV D) III ve IV E) III ve IV

How i can reverse match the regex that i wrote?

I need to reverse match the text because it can be everything on this block. A) example B) hello C) world D) goodbye E) something else

Thank you,

http://regexr.com/3a8fq

Burak Tamtürk
  • 1,237
  • 8
  • 19

3 Answers3

2

This should do the trick:

(?<=[A-E]\) ).*?(?= [A-E]\)|$)
AMDcze
  • 516
  • 3
  • 13
2

I would consider using a lookahead based regex.

(?s)[A-E]\)\s*((?:(?!\s*[A-E]\)).)+)
hwnd
  • 69,796
  • 4
  • 95
  • 132
0

you can also do

/I(II)? ve I(I|V)/

If your language supports inverse lookaheads:

?!(?:[A|B|C|D|E]\) )
La-comadreja
  • 5,627
  • 11
  • 36
  • 64
  • So long as the answers always take that format, sure, but I'm guessing that they might not, and the idea is to key off the labels. – Scott Hunter Jan 20 '15 at 19:51
  • Thank you, but i forgot to mention it can be everyting on this block. A) example B) hello C) world D) goodbye E) something else – Burak Tamtürk Jan 20 '15 at 19:51