Java/Quickrex regex: missing character in group when using negative lookahaed -


in java (using eclipse quickrex plugin test) i'm using following expression:

(^[\.\(&\)]*)(.*)(?!([\.\(&/\)]*$))

to match text:

.(&&()..abc----....d25..../)(&

the expected goal match 3 groups:

(1) .(&&()..

(2) abc----....d25

(3) ..../)(&

the goal further continue 2nd group , cut preceeding group no.1 , subsequent group no.3. requirement user should define 3 regex expressions himself in 3 separate gui fields.

what happening: 3 groups match fine in quickrex, in group no.2 abc----....d2 "5" @ end missing, , not appearing in group no.3:

[.(&&()..][abc----....d2]5[..../)(&]

environment: eclipse mars 4.5.2, java 1.8.0_66, quickrex 4.3.0

two questions:

is proper way match these groups?

is there logical reason why "5" not included or bug in regex engine?

5 not included because cannot matched due negative lookahead (?![.(&/)]*$) makes engine backtrack , find 2 not followed ., (, &, /, or ) symbols.

to match 2 groups need (as mention, 3rd 1 discarded anyway), may turn greedy * quantifier in second group lazy 1 *? (to match few chars other newline before firs occurrence of subsequent subpattern) , turn negative lookahead group (to make .*? stop right before pattern):

^([.(&)]*)(.*?)([.(&/)]*$) 

see regex demo

details:

  • ^ - start of string/line
  • ([.(&)]*) - group 1 capturing 0 or more characters character class
  • (.*?) - 0+ characters other newline few possible first
  • ([.(&/)]*$) - ., or (, or &, or /, or ), 0 or more occurrences end of string.

Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -