perl - PCRE Regex help needed -


i having trouble writing perl compatible regex match few different things when there gap between each condition. makes more sense when explain want find

conditions

  1. /world/
  2. a single letter
  3. a dash or underscore
  4. a single letter
  5. a single period
  6. three or 4 letters

the problem have don't know how write expression such there can gap between condition #1 , #2. conditions #2 - #4 can repeat, not always.

i've been using multiple online regex testers cannot match , not sure doing wrong. think regex looking /world/x_x or /world/y-y instead of "looking ahead" match on "letter dash letter" or "letter underscore letter" pattern.

current regex

/world/([a-z](-|_)[a-z]){1,}\.[a-z]{3,4}$ 

desired matches (not matching)

hxxp://armassimchilzeispreu.blackjackipad.com/world/activate_available.jar  hxxp://chubfaceddamsel0.affittobarcheavela.it/world/eternal_threat-clearing.html  hxxp://offdestroyengarabitar.freebookofraslot.com/world/bonus-middle-marathon.pdf 

i think want this

use strict; use warnings;  while (<data>) {   chomp;   print "ok $_\n" if m</world/[a-z]+(?:[_-][a-z]+)+\.[a-z]{3,4}$>; }  __data__ hxxp://armassimchilzeispreu.blackjackipad.com/world/activate_available.jar hxxp://chubfaceddamsel0.affittobarcheavela.it/world/eternal_threat-clearing.html hxxp://offdestroyengarabitar.freebookofraslot.com/world/bonus-middle-marathon.pdf 

or perhaps just

m</world/[a-z-_]+\.[a-z]{3,4}$> 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -