P e r l d o c B r o w s e r
●
5 . 1 8 . 3
L a t e s t
5 . 4 0 . 0
5 . 3 8 . 2
5 . 3 8 . 1
5 . 3 8 . 0
5 . 3 6 . 3
5 . 3 6 . 2
5 . 3 6 . 1
5 . 3 6 . 0
5 . 3 4 . 3
5 . 3 4 . 2
5 . 3 4 . 1
5 . 3 4 . 0
5 . 3 2 . 1
5 . 3 2 . 0
5 . 3 0 . 3
5 . 3 0 . 2
5 . 3 0 . 1
5 . 3 0 . 0
5 . 2 8 . 3
5 . 2 8 . 2
5 . 2 8 . 1
5 . 2 8 . 0
5 . 2 6 . 3
5 . 2 6 . 2
5 . 2 6 . 1
5 . 2 6 . 0
5 . 2 4 . 4
5 . 2 4 . 3
5 . 2 4 . 2
5 . 2 4 . 1
5 . 2 4 . 0
5 . 2 2 . 4
5 . 2 2 . 3
5 . 2 2 . 2
5 . 2 2 . 1
5 . 2 2 . 0
5 . 2 0 . 3
5 . 2 0 . 2
5 . 2 0 . 1
5 . 2 0 . 0
5 . 1 8 . 4
5 . 1 8 . 3
5 . 1 8 . 2
5 . 1 8 . 1
5 . 1 8 . 0
5 . 1 6 . 3
5 . 1 6 . 2
5 . 1 6 . 1
5 . 1 6 . 0
5 . 1 4 . 4
5 . 1 4 . 3
5 . 1 4 . 2
5 . 1 4 . 1
5 . 1 4 . 0
5 . 1 2 . 5
5 . 1 2 . 4
5 . 1 2 . 3
5 . 1 2 . 2
5 . 1 2 . 1
5 . 1 2 . 0
5 . 1 0 . 1
5 . 1 0 . 0
5 . 8 . 9
5 . 8 . 8
5 . 8 . 7
5 . 8 . 6
5 . 8 . 5
5 . 8 . 4
5 . 8 . 3
5 . 8 . 2
5 . 8 . 1
5 . 8 . 0
5 . 6 . 2
5 . 6 . 1
5 . 6 . 0
5 . 0 0 5 _ 0 4
5 . 0 0 5 _ 0 3
5 . 0 0 5 _ 0 2
5 . 0 0 5 _ 0 1
5 . 0 0 5
●
D e v
b l e a d
5 . 4 1 . 2
5 . 4 1 . 1
5 . 4 0 . 0 - R C 2
5 . 4 0 . 0 - R C 1
5 . 3 9 . 1 0
5 . 3 9 . 9
5 . 3 9 . 8
5 . 3 9 . 6
5 . 3 9 . 5
5 . 3 9 . 4
5 . 3 9 . 3
5 . 3 9 . 2
5 . 3 9 . 1
5 . 3 7 . 1 1
5 . 3 7 . 1 0
5 . 3 7 . 9
5 . 3 7 . 8
5 . 3 7 . 7
5 . 3 7 . 6
5 . 3 7 . 5
5 . 3 7 . 4
5 . 3 7 . 3
5 . 3 7 . 2
5 . 3 7 . 1
5 . 3 7 . 0
●
D o c u m e n t a t i o n
P e r l
I n t r o
T u t o r i a l s
F A Q s
R e f e r e n c e
O p e r a t o r s
F u n c t i o n s
V a r i a b l e s
M o d u l e s
U t i l i t i e s
C o m m u n i t y
H i s t o r y
E x p a n d
p e r l r e a p i
( s o u r c e ,
C P A N )
Y o u a r e v i e w i n g t h e v e r s i o n o f t h i s d o c u m e n t a t i o n f r o m P e r l 5 . 1 8 . 3 .
V i e w t h e l a t e s t v e r s i o n
●
N A M E
●
D E S C R I P T I O N
●
C a l l b a c k s
●
c o m p
●
e x e c
●
i n t u i t
●
c h e c k s t r
●
f r e e
●
N u m b e r e d c a p t u r e c a l l b a c k s
●
n u m b e r e d _ b u f f _ F E T C H
●
n u m b e r e d _ b u f f _ S T O R E
●
n u m b e r e d _ b u f f _ L E N G T H
●
N a m e d c a p t u r e c a l l b a c k s
●
n a m e d _ b u f f
●
n a m e d _ b u f f _ i t e r
●
q r _ p a c k a g e
●
d u p e
●
o p _ c o m p
●
T h e R E G E X P s t r u c t u r e
●
e n g i n e
●
m o t h e r _ r e
●
e x t f l a g s
●
m i n l e n m i n l e n r e t
●
g o f s
●
s u b s t r s
●
n p a r e n s , l a s t p a r e n , a n d l a s t c l o s e p a r e n
●
i n t f l a g s
●
p p r i v a t e
●
s w a p
●
o f f s
●
p r e c o m p p r e l e n
●
p a r e n _ n a m e s
●
s u b s t r s
●
s u b b e g s u b l e n s a v e d _ c o p y s u b o f f s e t s u b c o f f s e t
●
w r a p p e d w r a p l e n
●
s e e n _ e v a l s
●
r e f c n t
●
H I S T O R Y
●
A U T H O R S
●
L I C E N S E
# N A M E
p e r l r e a p i - P e r l r e g u l a r e x p r e s s i o n p l u g i n i n t e r f a c e
# D E S C R I P T I O N
A s o f P e r l 5 . 9 . 5 t h e r e i s a n e w i n t e r f a c e f o r p l u g g i n g a n d u s i n g r e g u l a r e x p r e s s i o n e n g i n e s o t h e r t h a n t h e d e f a u l t o n e .
E a c h e n g i n e i s s u p p o s e d t o p r o v i d e a c c e s s t o a c o n s t a n t s t r u c t u r e o f t h e f o l l o w i n g f o r m a t :
typedef struct regexp_engine {
REGEXP* (*comp) (pTHX_
const SV * const pattern, const U32 flags);
I32 (*exec) (pTHX_
REGEXP * const rx,
char* stringarg,
char* strend, char* strbeg,
I32 minend, SV* screamer,
void* data, U32 flags);
char* (*intuit) (pTHX_
REGEXP * const rx, SV *sv,
char *strpos, char *strend, U32 flags,
struct re_scream_pos_data_s *data);
SV* (*checkstr) (pTHX_ REGEXP * const rx);
void (*free) (pTHX_ REGEXP * const rx);
void (*numbered_buff_FETCH) (pTHX_
REGEXP * const rx,
const I32 paren,
SV * const sv);
void (*numbered_buff_STORE) (pTHX_
REGEXP * const rx,
const I32 paren,
SV const * const value);
I32 (*numbered_buff_LENGTH) (pTHX_
REGEXP * const rx,
const SV * const sv,
const I32 paren);
SV* (*named_buff) (pTHX_
REGEXP * const rx,
SV * const key,
SV * const value,
U32 flags);
SV* (*named_buff_iter) (pTHX_
REGEXP * const rx,
const SV * const lastkey,
const U32 flags);
SV* (*qr_package)(pTHX_ REGEXP * const rx);
#ifdef USE_ITHREADS
void* (*dupe) (pTHX_ REGEXP * const rx, CLONE_PARAMS *param);
#endif
REGEXP* (*op_comp) (...);
W h e n a r e g e x p i s c o m p i l e d , i t s e
n g i n e
f i e l d i s t h e n s e t t o p o i n t a t t h e a p p r o p r i a t e s t r u c t u r e , s o t h a t w h e n i t n e e d s t o b e u s e d P e r l c a n f i n d t h e r i g h t r o u t i n e s t o d o s o .
I n o r d e r t o i n s t a l l a n e w r e g e x p h a n d l e r , $ ^ H { r e g c o m p }
i s s e t t o a n i n t e g e r w h i c h ( w h e n c a s t e d a p p r o p r i a t e l y ) r e s o l v e s t o o n e o f t h e s e s t r u c t u r e s . W h e n c o m p i l i n g , t h e c o m p
m e t h o d i s e x e c u t e d , a n d t h e r e s u l t i n g r e g e x p
s t r u c t u r e ' s e n g i n e f i e l d i s e x p e c t e d t o p o i n t b a c k a t t h e s a m e s t r u c t u r e .
T h e p T H X _ s y m b o l i n t h e d e f i n i t i o n i s a m a c r o u s e d b y P e r l u n d e r t h r e a d i n g t o p r o v i d e a n e x t r a a r g u m e n t t o t h e r o u t i n e h o l d i n g a p o i n t e r b a c k t o t h e i n t e r p r e t e r t h a t i s e x e c u t i n g t h e r e g e x p . S o u n d e r t h r e a d i n g a l l r o u t i n e s g e t a n e x t r a a r g u m e n t .
# C a l l b a c k s
# c o m p
REGEXP* comp(pTHX_ const SV * const pattern, const U32 flags);
C o m p i l e t h e p a t t e r n s t o r e d i n p a
t t e r n
u s i n g t h e g i v e n f l a g s
a n d r e t u r n a p o i n t e r t o a p r e p a r e d R
E G E X P
s t r u c t u r e t h a t c a n p e r f o r m t h e m a t c h . S e e " T h e R E G E X P s t r u c t u r e " b e l o w f o r a n e x p l a n a t i o n o f t h e i n d i v i d u a l f i e l d s i n t h e R E G E X P s t r u c t .
T h e p a t t e r n
p a r a m e t e r i s t h e s c a l a r t h a t w a s u s e d a s t h e p a t t e r n . P r e v i o u s v e r s i o n s o f P e r l w o u l d p a s s t w o c h a r *
i n d i c a t i n g t h e s t a r t a n d e n d o f t h e s t r i n g i f i e d p a t t e r n ; t h e f o l l o w i n g s n i p p e t c a n b e u s e d t o g e t t h e o l d p a r a m e t e r s :
STRLEN plen;
char* exp = SvPV(pattern, plen);
char* xend = exp + plen;
S i n c e a n y s c a l a r c a n b e p a s s e d a s a p a t t e r n , i t ' s p o s s i b l e t o i m p l e m e n t a n e n g i n e t h a t d o e s s o m e t h i n g w i t h a n a r r a y ( " o o k " = ~ [
q w / e e k h l a g h / ]
) o r w i t h t h e n o n - s t r i n g i f i e d f o r m o f a c o m p i l e d r e g u l a r e x p r e s s i o n ( " o o k " = ~ q
r / e e k /
) . P e r l ' s o w n e n g i n e w i l l a l w a y s s t r i n g i f y e v e r y t h i n g u s i n g t h e s n i p p e t a b o v e , b u t t h a t d o e s n ' t m e a n o t h e r e n g i n e s h a v e t o .
T h e f l a g s
p a r a m e t e r i s a b i t f i e l d w h i c h i n d i c a t e s w h i c h o f t h e m
s i x p
f l a g s t h e r e g e x w a s c o m p i l e d w i t h . I t a l s o c o n t a i n s a d d i t i o n a l i n f o , s u c h a s i f u s e l o c a l e
i s i n e f f e c t .
T h e e o g c
f l a g s a r e s t r i p p e d o u t b e f o r e b e i n g p a s s e d t o t h e c o m p r o u t i n e . T h e r e g e x e n g i n e d o e s n o t n e e d t o k n o w i f a n y o f t h e s e a r e s e t , a s t h o s e f l a g s s h o u l d o n l y a f f e c t w h a t P e r l d o e s w i t h t h e p a t t e r n a n d i t s m a t c h v a r i a b l e s , n o t h o w i t g e t s c o m p i l e d a n d e x e c u t e d .
B y t h e t i m e t h e c o m p c a l l b a c k i s c a l l e d , s o m e o f t h e s e f l a g s h a v e a l r e a d y h a d e f f e c t ( n o t e d b e l o w w h e r e a p p l i c a b l e ) . H o w e v e r m o s t o f t h e i r e f f e c t o c c u r s a f t e r t h e c o m p c a l l b a c k h a s r u n , i n r o u t i n e s t h a t r e a d t h e r x - > e x t f l a g s
f i e l d w h i c h i t p o p u l a t e s .
I n g e n e r a l t h e f l a g s s h o u l d b e p r e s e r v e d i n r x - > e x t f l a g s
a f t e r c o m p i l a t i o n , a l t h o u g h t h e r e g e x e n g i n e m i g h t w a n t t o a d d o r d e l e t e s o m e o f t h e m t o i n v o k e o r d i s a b l e s o m e s p e c i a l b e h a v i o r i n P e r l . T h e f l a g s a l o n g w i t h a n y s p e c i a l b e h a v i o r t h e y c a u s e a r e d o c u m e n t e d b e l o w :
T h e p a t t e r n m o d i f i e r s :
# / m
- R X f _ P M f _ M U L T I L I N E
I f t h i s i s i n r x - > e x t f l a g s
i t w i l l b e p a s s e d t o P e r l _ f b m _ i n s t r
by p p _ s p l i t
w h i c h w i l l t r e a t t h e s u b j e c t s t r i n g a s a m u l t i - l i n e s t r i n g .
# / s
- R X f _ P M f _ S I N G L E L I N E
# / i
- R X f _ P M f _ F O L D
# / x
- R X f _ P M f _ E X T E N D E D
I f p r e s e n t o n a r e g e x , " # "
c o m m e n t s w i l l b e h a n d l e d d i f f e r e n t l y b y t h e t o k e n i z e r i n s o m e c a s e s .
T O D O : D o c u m e n t t h o s e c a s e s .
# / p
- R X f _ P M f _ K E E P C O P Y
T O D O : D o c u m e n t t h i s
# C h a r a c t e r s e t
T h e c h a r a c t e r s e t s e m a n t i c s a r e d e t e r m i n e d b y a n e n u m t h a t i s c o n t a i n e d i n t h i s f i e l d . T h i s i s s t i l l e x p e r i m e n t a l a n d s u b j e c t t o c h a n g e , b u t t h e c u r r e n t i n t e r f a c e r e t u r n s t h e r u l e s b y u s e o f t h e i n - l i n e f u n c t i o n g e t _ r
e g e x _ c h a r s e t ( c o n s t U 3 2 f l a g s )
. T h e o n l y c u r r e n t l y d o c u m e n t e d v a l u e r e t u r n e d f r o m i t i s R E G E X _ L O C A L E _ C H A R S E T , w h i c h i s s e t i f u s e l o c a l e
i s i n e f f e c t . I f p r e s e n t i n r x - > e x t f l a g s
, s p l i t
w i l l u s e t h e l o c a l e d e p e n d e n t d e f i n i t i o n o f w h i t e s p a c e w h e n R X f _ S K I P W H I T E o r R X f _ W H I T E i s i n e f f e c t . A S C I I w h i t e s p a c e i s d e f i n e d a s p e r i s S P A C E , a n d b y t h e i n t e r n a l m a c r o s i s _ u t f 8 _ s p a c e
u n d e r U T F - 8 , a n d i s S P A C E _ L C
u n d e r u s e l o c a l e
.
A d d i t i o n a l f l a g s :
# R X f _ S P L I T
T h i s f l a g w a s r e m o v e d i n p e r l 5 . 1 8 . 0 . s p l i t ' '
i s n o w s p e c i a l - c a s e d s o l e l y i n t h e p a r s e r . R X f _ S P L I T i s s t i l l # d e f i n e d , s o y o u c a n t e s t f o r i t . T h i s i s h o w i t u s e d t o w o r k :
If s p l i t
i s i n v o k e d a s s p l i t ' '
o r w i t h n o a r g u m e n t s ( w h i c h r e a l l y m e a n s s p l i t ( ' ' , $ _ )
, s e e s p l i t ) , P e r l w i l l s e t t h i s f l a g . T h e r e g e x e n g i n e c a n t h e n c h e c k f o r i t a n d s e t t h e S K I P W H I T E a n d W H I T E e x t f l a g s . T o d o t h i s , t h e P e r l e n g i n e d o e s :
if (flags & RXf_SPLIT && r->prelen == 1 && r->precomp[0] == ' ')
r->extflags |= (RXf_SKIPWHITE|RXf_WHITE);
T h e s e f l a g s c a n b e s e t d u r i n g c o m p i l a t i o n t o e n a b l e o p t i m i z a t i o n s i n t h e s p l i t
o p e r a t o r .
# R X f _ S K I P W H I T E
T h i s f l a g w a s r e m o v e d i n p e r l 5 . 1 8 . 0 . I t i s s t i l l # d e f i n e d , s o y o u c a n s e t i t , b u t d o i n g s o w i l l h a v e n o e f f e c t . T h i s i s h o w i t u s e d t o w o r k :
I f t h e f l a g i s p r e s e n t i n r x - > e
x t f l a g s
s p l i t
w i l l d e l e t e w h i t e s p a c e f r o m t h e s t a r t o f t h e s u b j e c t s t r i n g b e f o r e i t ' s o p e r a t e d o n . W h a t i s c o n s i d e r e d w h i t e s p a c e d e p e n d s o n i f t h e s u b j e c t i s a U T F - 8 s t r i n g a n d i f t h e R X
f _ P M f _ L O C A L E
f l a g i s s e t .
I f R X f _ W H I T E i s s e t i n a d d i t i o n t o t h i s f l a g , s p l i t
w i l l b e h a v e l i k e s p l i t " "
u n d e r t h e P e r l e n g i n e .
# R X f _ S T A R T _ O N L Y
T e l l s t h e s p l i t o p e r a t o r t o s p l i t t h e t a r g e t s t r i n g o n n e w l i n e s ( \ n
) w i t h o u t i n v o k i n g t h e r e g e x e n g i n e .
P e r l ' s e n g i n e s e t s t h i s i f t h e p a t t e r n i s / ^ /
( p l e n = = 1 & & * e
x p = = ' ^ '
) , e v e n u n d e r / ^ / s
; s e e s p l i t . O f c o u r s e a d i f f e r e n t r e g e x e n g i n e m i g h t w a n t t o u s e t h e s a m e o p t i m i z a t i o n s w i t h a d i f f e r e n t s y n t a x .
# R X f _ W H I T E
T e l l s t h e s p l i t o p e r a t o r t o s p l i t t h e t a r g e t s t r i n g o n w h i t e s p a c e w i t h o u t i n v o k i n g t h e r e g e x e n g i n e . T h e d e f i n i t i o n o f w h i t e s p a c e v a r i e s d e p e n d i n g o n i f t h e t a r g e t s t r i n g i s a U T F - 8 s t r i n g a n d o n i f R X f _ P M f _ L O C A L E i s s e t .
P e r l ' s e n g i n e s e t s t h i s f l a g i f t h e p a t t e r n i s \ s +
.
# R X f _ N U L L
T e l l s t h e s p l i t o p e r a t o r t o s p l i t t h e t a r g e t s t r i n g o n c h a r a c t e r s . T h e d e f i n i t i o n o f c h a r a c t e r v a r i e s d e p e n d i n g o n i f t h e t a r g e t s t r i n g i s a U T F - 8 s t r i n g .
P e r l ' s e n g i n e s e t s t h i s f l a g o n e m p t y p a t t e r n s , t h i s o p t i m i z a t i o n m a k e s s p l i t / /
m u c h f a s t e r t h a n i t w o u l d o t h e r w i s e b e . I t ' s e v e n f a s t e r t h a n u n p a c k
.
# R X f _ N O _ I N P L A C E _ S U B S T
A d d e d i n p e r l 5 . 1 8 . 0 , t h i s f l a g i n d i c a t e s t h a t a r e g u l a r e x p r e s s i o n m i g h t p e r f o r m a n o p e r a t i o n t h a t w o u l d i n t e r f e r e w i t h i n p l a c e s u b s t i t u i o n . F o r i n s t a n c e i t m i g h t c o n t a i n l o o k b e h i n d , o r a s s i g n t o n o n - m a g i c a l v a r i a b l e s ( s u c h a s $ R E G M A R K a n d $ R E G E R R O R ) d u r i n g m a t c h i n g . s / / /
w i l l s k i p c e r t a i n o p t i m i s a t i o n s w h e n t h i s i s s e t .
# e x e c
I32 exec(pTHX_ REGEXP * const rx,
char *stringarg, char* strend, char* strbeg,
I32 minend, SV* screamer,
void* data, U32 flags);
E x e c u t e a r e g e x p . T h e a r g u m e n t s a r e
# rx
T h e r e g u l a r e x p r e s s i o n t o e x e c u t e .
# s c r e a m e r
T h i s s t r a n g e l y - n a m e d a r g i s t h e S V t o b e m a t c h e d a g a i n s t . N o t e t h a t t h e a c t u a l c h a r a r r a y t o b e m a t c h e d a g a i n s t i s s u p p l i e d b y t h e a r g u m e n t s d e s c r i b e d b e l o w ; t h e S V i s j u s t u s e d t o d e t e r m i n e U T F 8 n e s s , p o s ( )
e t c .
# s t r b e g
P o i n t e r t o t h e p h y s i c a l s t a r t o f t h e s t r i n g .
# s t r e n d
P o i n t e r t o t h e c h a r a c t e r f o l l o w i n g t h e p h y s i c a l e n d o f t h e s t r i n g ( i . e . t h e \ 0
) .
# s t r i n g a r g
P o i n t e r t o t h e p o s i t i o n i n t h e s t r i n g w h e r e m a t c h i n g s h o u l d s t a r t ; i t m i g h t n o t b e e q u a l t o s
t r b e g
( f o r e x a m p l e i n a l a t e r i t e r a t i o n o f / . . . / g
) .
# m i n e n d
M i n i m u m l e n g t h o f s t r i n g ( m e a s u r e d i n b y t e s f r o m s t r i n g a r g
) t h a t m u s t m a t c h ; i f t h e e n g i n e r e a c h e s t h e e n d o f t h e m a t c h b u t h a s n ' t r e a c h e d t h i s p o s i t i o n i n t h e s t r i n g , i t s h o u l d f a i l .
# d a t a
O p t i m i s a t i o n d a t a ; s u b j e c t t o c h a n g e .
# f l a g s
O p t i m i s a t i o n f l a g s ; s u b j e c t t o c h a n g e .
# i n t u i t
char* intuit(pTHX_ REGEXP * const rx,
SV *sv, char *strpos, char *strend,
const U32 flags, struct re_scream_pos_data_s *data);
F i n d t h e s t a r t p o s i t i o n w h e r e a r e g e x m a t c h s h o u l d b e a t t e m p t e d , o r p o s s i b l y i f t h e r e g e x e n g i n e s h o u l d n o t b e r u n b e c a u s e t h e p a t t e r n c a n ' t m a t c h . T h i s i s c a l l e d , a s a p p r o p r i a t e , b y t h e c o r e , d e p e n d i n g o n t h e v a l u e s o f t h e e x t f l a g s
m e m b e r o f t h e r e g e x p
s t r u c t u r e .
# c h e c k s t r
SV* checkstr(pTHX_ REGEXP * const rx);
R e t u r n a S V c o n t a i n i n g a s t r i n g t h a t m u s t a p p e a r i n t h e p a t t e r n . U s e d b y s p l i t
f o r o p t i m i s i n g m a t c h e s .
# f r e e
void free(pTHX_ REGEXP * const rx);
C a l l e d b y P e r l w h e n i t i s f r e e i n g a r e g e x p p a t t e r n s o t h a t t h e e n g i n e c a n r e l e a s e a n y r e s o u r c e s p o i n t e d t o b y t h e p p r i v a t e
m e m b e r o f t h e r e g e x p
s t r u c t u r e . T h i s i s o n l y r e s p o n s i b l e f o r f r e e i n g p r i v a t e d a t a ; P e r l w i l l h a n d l e r e l e a s i n g a n y t h i n g e l s e c o n t a i n e d i n t h e r e g e x p
s t r u c t u r e .
# N u m b e r e d c a p t u r e c a l l b a c k s
C a l l e d t o g e t / s e t t h e v a l u e o f $
`
, $ '
, $ &
a n d t h e i r n a m e d e q u i v a l e n t s , $ { ^ P R E M A T C H } , $ { ^ P O S T M A T C H } a n d $ ^ { M A T C H } , a s w e l l a s t h e n u m b e r e d c a p t u r e g r o u p s ( $ 1
, $ 2
, . . . ) .
T h e p a r e n
p a r a m e t e r w i l l b e 1
f o r $ 1
, 2
f o r $ 2
a n d s o f o r t h , a n d h a v e t h e s e s y m b o l i c v a l u e s f o r t h e s p e c i a l v a r i a b l e s :
${^PREMATCH} RX_BUFF_IDX_CARET_PREMATCH
${^POSTMATCH} RX_BUFF_IDX_CARET_POSTMATCH
${^MATCH} RX_BUFF_IDX_CARET_FULLMATCH
$` RX_BUFF_IDX_PREMATCH
$' RX_BUFF_IDX_POSTMATCH
$& RX_BUFF_IDX_FULLMATCH
N o t e t h a t i n P e r l 5 . 1 7 . 3 a n d e a r l i e r , t h e l a s t t h r e e c o n s t a n t s w e r e a l s o u s e d f o r t h e c a r e t v a r i a n t s o f t h e v a r i a b l e s .
T h e n a m e s h a v e b e e n c h o s e n b y a n a l o g y w i t h T i e : : S c a l a r m e t h o d s n a m e s w i t h a n a d d i t i o n a l L E N G T H c a l l b a c k f o r e f f i c i e n c y . H o w e v e r n a m e d c a p t u r e v a r i a b l e s a r e c u r r e n t l y n o t t i e d i n t e r n a l l y b u t i m p l e m e n t e d v i a m a g i c .
# n u m b e r e d _ b u f f _ F E T C H
void numbered_buff_FETCH(pTHX_ REGEXP * const rx, const I32 paren,
SV * const sv);
F e t c h a s p e c i f i e d n u m b e r e d c a p t u r e . sv
s h o u l d b e s e t t o t h e s c a l a r t o r e t u r n , t h e s c a l a r i s p a s s e d a s a n a r g u m e n t r a t h e r t h a n b e i n g r e t u r n e d f r o m t h e f u n c t i o n b e c a u s e w h e n i t ' s c a l l e d P e r l a l r e a d y h a s a s c a l a r t o s t o r e t h e v a l u e , c r e a t i n g a n o t h e r o n e w o u l d b e r e d u n d a n t . T h e s c a l a r c a n b e s e t w i t h s v _ s e t s v
, s v _ s e t p v n
a n d f r i e n d s , s e e p e r l a p i .
T h i s c a l l b a c k i s w h e r e P e r l u n t a i n t s i t s o w n c a p t u r e v a r i a b l e s u n d e r t a i n t m o d e ( s e e p e r l s e c ) . S e e t h e P e r l _ r e g _ n u m b e r e d _ b u f f _ f e
t c h
f u n c t i o n i n r e g c o m p . c f o r h o w t o u n t a i n t c a p t u r e v a r i a b l e s i f t h a t ' s s o m e t h i n g y o u ' d l i k e y o u r e n g i n e t o d o a s w e l l .
# n u m b e r e d _ b u f f _ S T O R E
void (*numbered_buff_STORE) (pTHX_
REGEXP * const rx,
const I32 paren,
SV const * const value);
S e t t h e v a l u e o f a n u m b e r e d c a p t u r e v a r i a b l e . v a l u e
i s t h e s c a l a r t h a t i s t o b e u s e d a s t h e n e w v a l u e . I t ' s u p t o t h e e n g i n e t o m a k e s u r e t h i s i s u s e d a s t h e n e w v a l u e ( o r r e j e c t i t ) .
E x a m p l e :
if ("ook" =~ /(o*)/) {
# 'paren' will be '1' and 'value' will be 'ee'
$1 =~ tr/o/e/;
}
P e r l ' s o w n e n g i n e w i l l c r o a k o n a n y a t t e m p t t o m o d i f y t h e c a p t u r e v a r i a b l e s , t o d o t h i s i n a n o t h e r e n g i n e u s e t h e f o l l o w i n g c a l l b a c k ( c o p i e d f r o m P e r l _ r e g _ n u m b e
r e d _ b u f f _ s t o r e
) :
void
Example_reg_numbered_buff_store(pTHX_
REGEXP * const rx,
const I32 paren,
SV const * const value)
{
PERL_UNUSED_ARG(rx );
PERL_UNUSED_ARG(paren);
PERL_UNUSED_ARG(value);
if (!PL_localizing)
Perl_croak(aTHX_ PL_no_modify);
}
A c t u a l l y P e r l w i l l n o t a l w a y s c r o a k i n a s t a t e m e n t t h a t l o o k s l i k e i t w o u l d m o d i f y a n u m b e r e d c a p t u r e v a r i a b l e . T h i s i s b e c a u s e t h e S T O R E c a l l b a c k w i l l n o t b e c a l l e d i f P e r l c a n d e t e r m i n e t h a t i t d o e s n ' t h a v e t o m o d i f y t h e v a l u e . T h i s i s e x a c t l y h o w t i e d v a r i a b l e s b e h a v e i n t h e s a m e s i t u a t i o n :
package CaptureVar;
use base 'Tie::Scalar';
sub TIESCALAR { bless [] }
sub FETCH { undef }
sub STORE { die "This doesn't get called" }
package main;
tie my $sv => "CaptureVar";
$sv =~ y/a/b/;
B e c a u s e $ s v
is u n d e f
w h e n t h e y / / /
o p e r a t o r i s a p p l i e d t o i t , t h e t r a n s l i t e r a t i o n w o n ' t a c t u a l l y e x e c u t e a n d t h e p r o g r a m w o n ' t d i e
. T h i s i s d i f f e r e n t t o h o w 5 . 8 a n d e a r l i e r v e r s i o n s b e h a v e d s i n c e t h e c a p t u r e v a r i a b l e s w e r e R E A D O N L Y v a r i a b l e s t h e n ; n o w t h e y ' l l j u s t d i e w h e n a s s i g n e d t o i n t h e d e f a u l t e n g i n e .
# n u m b e r e d _ b u f f _ L E N G T H
I32 numbered_buff_LENGTH (pTHX_
REGEXP * const rx,
const SV * const sv,
const I32 paren);
G e t t h e l e n g t h
o f a c a p t u r e v a r i a b l e . T h e r e ' s a s p e c i a l c a l l b a c k f o r t h i s s o t h a t P e r l d o e s n ' t h a v e t o d o a F E T C H a n d r u n l e n g t h
o n t h e r e s u l t , s i n c e t h e l e n g t h i s ( i n P e r l ' s c a s e ) k n o w n f r o m a n o f f s e t s t o r e d i n r x - > o f f s
, t h i s i s m u c h m o r e e f f i c i e n t :
I32 s1 = rx->offs[paren].start;
I32 s2 = rx->offs[paren].end;
I32 len = t1 - s1;
T h i s i s a l i t t l e b i t m o r e c o m p l e x i n t h e c a s e o f U T F - 8 , s e e w h a t P e r l _ r e g _ n u m b e r e d _ b u f f _ l e n g t h
d o e s w i t h i s _ u t f 8 _ s t r i n g _ l o c l e n .
# N a m e d c a p t u r e c a l l b a c k s
C a l l e d t o g e t / s e t t h e v a l u e o f %
+
a n d % -
, a s w e l l a s b y s o m e u t i l i t y f u n c t i o n s i n re .
T h e r e a r e t w o c a l l b a c k s , n a m e d _ b
u f f
i s c a l l e d i n a l l t h e c a s e s t h e F E T C H , S T O R E , D E L E T E , C L E A R , E X I S T S a n d S C A L A R T i e : : H a s h c a l l b a c k s w o u l d b e o n c h a n g e s t o % +
a n d % -
a n d n a m e d _ b u f f _ i t e r
i n t h e s a m e c a s e s a s F I R S T K E Y a n d N E X T K E Y .
T h e f l a g s
p a r a m e t e r c a n b e u s e d t o d e t e r m i n e w h i c h o f t h e s e o p e r a t i o n s t h e c a l l b a c k s s h o u l d r e s p o n d t o . T h e f o l l o w i n g f l a g s a r e c u r r e n t l y d e f i n e d :
W h i c h T i e : : H a s h o p e r a t i o n i s b e i n g p e r f o r m e d f r o m t h e P e r l l e v e l o n % +
or % +
, i f a n y :
RXapif_FETCH
RXapif_STORE
RXapif_DELETE
RXapif_CLEAR
RXapif_EXISTS
RXapif_SCALAR
RXapif_FIRSTKEY
RXapif_NEXTKEY
If % +
or % -
i s b e i n g o p e r a t e d o n , i f a n y .
RXapif_ONE /* %+ */
RXapif_ALL /* %- */
I f t h i s i s b e i n g c a l l e d a s r e : : r
e g n a m e
, r e : : r e g n a m e s
or r e : : r e g n a m e
s _ c o u n t
, i f a n y . T h e f i r s t t w o w i l l b e c o m b i n e d w i t h R X a p i f _ O N E
or R X a p i f _ A L L
.
RXapif_REGNAME
RXapif_REGNAMES
RXapif_REGNAMES_COUNT
I n t e r n a l l y % +
a n d % -
a r e i m p l e m e n t e d w i t h a r e a l t i e d i n t e r f a c e v i a T i e : : H a s h : : N a m e d C a p t u r e . T h e m e t h o d s i n t h a t p a c k a g e w i l l c a l l b a c k i n t o t h e s e f u n c t i o n s . H o w e v e r t h e u s a g e o f T i e : : H a s h : : N a m e d C a p t u r e f o r t h i s p u r p o s e m i g h t c h a n g e i n f u t u r e r e l e a s e s . F o r i n s t a n c e t h i s m i g h t b e i m p l e m e n t e d b y m a g i c i n s t e a d ( w o u l d n e e d a n e x t e n s i o n t o m g v t b l ) .
# n a m e d _ b u f f
SV* (*named_buff) (pTHX_ REGEXP * const rx, SV * const key,
SV * const value, U32 flags);
# n a m e d _ b u f f _ i t e r
SV* (*named_buff_iter) (pTHX_
REGEXP * const rx,
const SV * const lastkey,
const U32 flags);
# q r _ p a c k a g e
SV* qr_package(pTHX_ REGEXP * const rx);
T h e p a c k a g e t h e q r / / m a g i c o b j e c t i s b l e s s e d i n t o ( a s s e e n b y r e
f q r / /
) . I t i s r e c o m m e n d e d t h a t e n g i n e s c h a n g e t h i s t o t h e i r p a c k a g e n a m e f o r i d e n t i f i c a t i o n r e g a r d l e s s o f i f t h e y i m p l e m e n t m e t h o d s o n t h e o b j e c t .
T h e p a c k a g e t h i s m e t h o d r e t u r n s s h o u l d a l s o h a v e t h e i n t e r n a l R e
g e x p
p a c k a g e i n i t s @ I S A
. q r / / - >
i s a ( " R e g e x p " )
s h o u l d a l w a y s b e t r u e r e g a r d l e s s o f w h a t e n g i n e i s b e i n g u s e d .
E x a m p l e i m p l e m e n t a t i o n m i g h t b e :
SV*
Example_qr_package(pTHX_ REGEXP * const rx)
{
PERL_UNUSED_ARG(rx );
return newSVpvs("re::engine::Example");
}
A n y m e t h o d c a l l s o n a n o b j e c t c r e a t e d w i t h q r / /
w i l l b e d i s p a t c h e d t o t h e p a c k a g e a s a n o r m a l o b j e c t .
use re::engine::Example;
my $re = qr//;
$re->meth; # dispatched to re::engine::Example::meth()
T o r e t r i e v e t h e R E G E X P
o b j e c t f r o m t h e s c a l a r i n a n X S f u n c t i o n u s e t h e S v R X
m a c r o , s e e " R E G E X P F u n c t i o n s " i n p e r l a p i .
void meth(SV * rv)
PPCODE:
REGEXP * re = SvRX(sv );
# d u p e
void* dupe(pTHX_ REGEXP * const rx, CLONE_PARAMS *param);
O n t h r e a d e d b u i l d s a r e g e x p m a y n e e d t o b e d u p l i c a t e d s o t h a t t h e p a t t e r n c a n b e u s e d b y m u l t i p l e t h r e a d s . T h i s r o u t i n e i s e x p e c t e d t o h a n d l e t h e d u p l i c a t i o n o f a n y p r i v a t e d a t a p o i n t e d t o b y t h e p p r i v a t e
m e m b e r o f t h e r e g e x
p
s t r u c t u r e . I t w i l l b e c a l l e d w i t h t h e p r e c o n s t r u c t e d n e w r e g e x
p
s t r u c t u r e a s a n a r g u m e n t , t h e p p r i v a t e
m e m b e r w i l l p o i n t a t t h e o l d p r i v a t e s t r u c t u r e , a n d i t i s t h i s r o u t i n e ' s r e s p o n s i b i l i t y t o c o n s t r u c t a c o p y a n d r e t u r n a p o i n t e r t o i t ( w h i c h P e r l w i l l t h e n u s e t o o v e r w r i t e t h e f i e l d a s p a s s e d t o t h i s r o u t i n e . )
T h i s a l l o w s t h e e n g i n e t o d u p e i t s p r i v a t e d a t a b u t a l s o i f n e c e s s a r y m o d i f y t h e f i n a l s t r u c t u r e i f i t r e a l l y m u s t .
O n u n t h r e a d e d b u i l d s t h i s f i e l d d o e s n ' t e x i s t .
# o p _ c o m p
T h i s i s p r i v a t e t o t h e P e r l c o r e a n d s u b j e c t t o c h a n g e . S h o u l d b e l e f t n u l l .
# T h e R E G E X P s t r u c t u r e
T h e R E G E X P s t r u c t i s d e f i n e d i n r e g e x p . h . A l l r e g e x e n g i n e s m u s t b e a b l e t o c o r r e c t l y b u i l d s u c h a s t r u c t u r e i n t h e i r " c o m p " r o u t i n e .
T h e R E G E X P s t r u c t u r e c o n t a i n s a l l t h e d a t a t h a t P e r l n e e d s t o b e a w a r e o f t o p r o p e r l y w o r k w i t h t h e r e g u l a r e x p r e s s i o n . I t i n c l u d e s d a t a a b o u t o p t i m i s a t i o n s t h a t P e r l c a n u s e t o d e t e r m i n e i f t h e r e g e x e n g i n e s h o u l d r e a l l y b e u s e d , a n d v a r i o u s o t h e r c o n t r o l i n f o t h a t i s n e e d e d t o p r o p e r l y e x e c u t e p a t t e r n s i n v a r i o u s c o n t e x t s , s u c h a s i f t h e p a t t e r n a n c h o r e d i n s o m e w a y , o r w h a t f l a g s w e r e u s e d d u r i n g t h e c o m p i l e , o r i f t h e p r o g r a m c o n t a i n s s p e c i a l c o n s t r u c t s t h a t P e r l n e e d s t o b e a w a r e o f .
I n a d d i t i o n i t c o n t a i n s t w o f i e l d s t h a t a r e i n t e n d e d f o r t h e p r i v a t e u s e o f t h e r e g e x e n g i n e t h a t c o m p i l e d t h e p a t t e r n . T h e s e a r e t h e i n t f l a g s
a n d p p r i v a t e
m e m b e r s . p p r i v a t e
i s a v o i d p o i n t e r t o a n a r b i t r a r y s t r u c t u r e , w h o s e u s e a n d m a n a g e m e n t i s t h e r e s p o n s i b i l i t y o f t h e c o m p i l i n g e n g i n e . P e r l w i l l n e v e r m o d i f y e i t h e r o f t h e s e v a l u e s .
typedef struct regexp {
/* what engine created this regexp? */
const struct regexp_engine* engine;
/* what re is this a lightweight copy of? */
struct regexp* mother_re;
/* Information about the match that the Perl core uses to manage
* things */
U32 extflags; /* Flags used both externally and internally */
I32 minlen; /* mininum possible number of chars in */
string to match */
I32 minlenret; /* mininum possible number of chars in $& */
U32 gofs; /* chars left of pos that we search from */
/* substring data about strings that must appear
in the final match, used for optimisations */
struct reg_substr_data *substrs;
U32 nparens; /* number of capture groups */
/* private engine specific data */
U32 intflags; /* Engine Specific Internal flags */
void *pprivate; /* Data private to the regex engine which
created this object. */
/* Data about the last/current match. These are modified during
* matching*/
U32 lastparen; /* highest close paren matched ($+) */
U32 lastcloseparen; /* last close paren matched ($^N) */
regexp_paren_pair *swap; /* Swap copy of *offs */
regexp_paren_pair *offs; /* Array of offsets for (@-) and
(@+) */
char *subbeg; /* saved or original string so \digit works
forever. */
SV_SAVED_COPY /* If non-NULL, SV which is COW from original */
I32 sublen; /* Length of string pointed by subbeg */
I32 suboffset; /* byte offset of subbeg from logical start of
str */
I32 subcoffset; /* suboffset equiv, but in chars (for @-/@+) */
/* Information about the match that isn't often used */
I32 prelen; /* length of precomp */
const char *precomp; /* pre-compilation regular expression */
char *wrapped; /* wrapped version of the pattern */
I32 wraplen; /* length of wrapped */
I32 seen_evals; /* number of eval groups in the pattern - for
security checks */
HV *paren_names; /* Optional hash of paren names */
/* Refcount of this regexp */
I32 refcnt; /* Refcount of this regexp */
} regexp;
T h e f i e l d s a r e d i s c u s s e d i n m o r e d e t a i l b e l o w :
# e n g i n e
T h i s f i e l d p o i n t s a t a r e g e x p _ e n
g i n e
s t r u c t u r e w h i c h c o n t a i n s p o i n t e r s t o t h e s u b r o u t i n e s t h a t a r e t o b e u s e d f o r p e r f o r m i n g a m a t c h . I t i s t h e c o m p i l i n g r o u t i n e ' s r e s p o n s i b i l i t y t o p o p u l a t e t h i s f i e l d b e f o r e r e t u r n i n g t h e r e g e x p o b j e c t .
I n t e r n a l l y t h i s i s s e t t o N U L L
u n l e s s a c u s t o m e n g i n e i s s p e c i f i e d i n $ ^ H { r e g c o m p }
, P e r l ' s o w n s e t o f c a l l b a c k s c a n b e a c c e s s e d i n t h e s t r u c t p o i n t e d t o b y R E _ E
N G I N E _ P T R
.
# m o t h e r _ r e
T O D O , s e e h t t p : / / w w w . m a i l - a r c h i v e . c o m / p e r l 5 - c h a n g e s @ p e r l . o r g / m s g 1 7 3 2 8 . h t m l
# e x t f l a g s
T h i s w i l l b e u s e d b y P e r l t o s e e w h a t f l a g s t h e r e g e x p w a s c o m p i l e d w i t h , t h i s w i l l n o r m a l l y b e s e t t o t h e v a l u e o f t h e f l a g s p a r a m e t e r b y t h e c o m p c a l l b a c k . S e e t h e c o m p d o c u m e n t a t i o n f o r v a l i d f l a g s .
# m i n l e n
m i n l e n r e t
T h e m i n i m u m s t r i n g l e n g t h ( i n c h a r a c t e r s ) r e q u i r e d f o r t h e p a t t e r n t o m a t c h . T h i s i s u s e d t o p r u n e t h e s e a r c h s p a c e b y n o t b o t h e r i n g t o m a t c h a n y c l o s e r t o t h e e n d o f a s t r i n g t h a n w o u l d a l l o w a m a t c h . F o r i n s t a n c e t h e r e i s n o p o i n t i n e v e n s t a r t i n g t h e r e g e x e n g i n e i f t h e m i n l e n i s 1 0 b u t t h e s t r i n g i s o n l y 5 c h a r a c t e r s l o n g . T h e r e i s n o w a y t h a t t h e p a t t e r n c a n m a t c h .
m i n l e n r e t
i s t h e m i n i m u m l e n g t h ( i n c h a r a c t e r s ) o f t h e s t r i n g t h a t w o u l d b e f o u n d i n $ & a f t e r a m a t c h .
T h e d i f f e r e n c e b e t w e e n m i n l e n
a n d m i n l e n r e t
c a n b e s e e n i n t h e f o l l o w i n g p a t t e r n :
/ns(?=\d)/
w h e r e t h e m i n l e n
w o u l d b e 3 b u t m i n l e n r e t
w o u l d o n l y b e 2 a s t h e \ d i s r e q u i r e d t o m a t c h b u t i s n o t a c t u a l l y i n c l u d e d i n t h e m a t c h e d c o n t e n t . T h i s d i s t i n c t i o n i s p a r t i c u l a r l y i m p o r t a n t a s t h e s u b s t i t u t i o n l o g i c u s e s t h e m i n l
e n r e t
t o t e l l i f i t c a n d o i n - p l a c e s u b s t i t u t i o n s ( t h e s e c a n r e s u l t i n c o n s i d e r a b l e s p e e d - u p ) .
# g o f s
L e f t o f f s e t f r o m p o s ( ) t o s t a r t m a t c h a t .
# s u b s t r s
S u b s t r i n g d a t a a b o u t s t r i n g s t h a t m u s t a p p e a r i n t h e f i n a l m a t c h . T h i s i s c u r r e n t l y o n l y u s e d i n t e r n a l l y b y P e r l ' s e n g i n e , b u t m i g h t b e u s e d i n t h e f u t u r e f o r a l l e n g i n e s f o r o p t i m i s a t i o n s .
# n p a r e n s
, l a s t p a r e n
, a n d l a s t c l o
s e p a r e n
T h e s e f i e l d s a r e u s e d t o k e e p t r a c k o f h o w m a n y p a r e n g r o u p s c o u l d b e m a t c h e d i n t h e p a t t e r n , w h i c h w a s t h e l a s t o p e n p a r e n t o b e e n t e r e d , a n d w h i c h w a s t h e l a s t c l o s e p a r e n t o b e e n t e r e d .
# i n t f l a g s
T h e e n g i n e ' s p r i v a t e c o p y o f t h e f l a g s t h e p a t t e r n w a s c o m p i l e d w i t h . U s u a l l y t h i s i s t h e s a m e a s e x t f l a g s
u n l e s s t h e e n g i n e c h o s e t o m o d i f y o n e o f t h e m .
# p p r i v a t e
A v o i d * p o i n t i n g t o a n e n g i n e - d e f i n e d d a t a s t r u c t u r e . T h e P e r l e n g i n e u s e s t h e r e g e x p _ i n t e r n a l
s t r u c t u r e ( s e e " B a s e S t r u c t u r e s " i n p e r l r e g u t s ) b u t a c u s t o m e n g i n e s h o u l d u s e s o m e t h i n g e l s e .
# s w a p
U n u s e d . L e f t i n f o r c o m p a t i b i l i t y w i t h P e r l 5 . 1 0 . 0 .
# o f f s
A r e g e x p _ p a r e n _ p a i r
s t r u c t u r e w h i c h d e f i n e s o f f s e t s i n t o t h e s t r i n g b e i n g m a t c h e d w h i c h c o r r e s p o n d t o t h e $ &
a n d $ 1
, $ 2
e t c . c a p t u r e s , t h e r e g e x p _ p a r e n _ p a i r
s t r u c t i s d e f i n e d a s f o l l o w s :
typedef struct regexp_paren_pair {
I32 start;
I32 end;
} regexp_paren_pair;
If - > o f f s [ n u m ] . s t a r t
or - > o f f s [ n u m ] . e
n d
is - 1
t h e n t h a t c a p t u r e g r o u p d i d n o t m a t c h . - > o f f s [ 0 ] . s t a r t / e n d
r e p r e s e n t s $ &
( or $ { ^ M A T C H }
u n d e r / / p
) a n d - > o f f s [ p a r e n ] . e n d
m a t c h e s $ $ p a r e n
w h e r e $ p a r e n
= 1 > .
# p r e c o m p
p r e l e n
U s e d f o r o p t i m i s a t i o n s . p r e c o m p
h o l d s a c o p y o f t h e p a t t e r n t h a t w a s c o m p i l e d a n d p r e l e n
i t s l e n g t h . W h e n a n e w p a t t e r n i s t o b e c o m p i l e d ( s u c h a s i n s i d e a l o o p ) t h e i n t e r n a l r e g c o m p
o p e r a t o r c h e c k s i f t h e l a s t c o m p i l e d R E G E X
P
' s p r e c o m p
a n d p r e l e n
a r e e q u i v a l e n t t o t h e n e w o n e , a n d i f s o u s e s t h e o l d p a t t e r n i n s t e a d o f c o m p i l i n g a n e w o n e .
T h e r e l e v a n t s n i p p e t f r o m P e r l _ p
p _ r e g c o m p
:
if (!re || !re->precomp || re->prelen != (I32)len ||
memNE(re->precomp, t, len))
/* Compile a new pattern */
# p a r e n _ n a m e s
T h i s i s a h a s h u s e d i n t e r n a l l y t o t r a c k n a m e d c a p t u r e g r o u p s a n d t h e i r o f f s e t s . T h e k e y s a r e t h e n a m e s o f t h e b u f f e r s t h e v a l u e s a r e d u a l v a r s , w i t h t h e I V s l o t h o l d i n g t h e n u m b e r o f b u f f e r s w i t h t h e g i v e n n a m e a n d t h e p v b e i n g a n e m b e d d e d a r r a y o f I 3 2 . T h e v a l u e s m a y a l s o b e c o n t a i n e d i n d e p e n d e n t l y i n t h e d a t a a r r a y i n c a s e s w h e r e n a m e d b a c k r e f e r e n c e s a r e u s e d .
# s u b s t r s
H o l d s i n f o r m a t i o n o n t h e l o n g e s t s t r i n g t h a t m u s t o c c u r a t a f i x e d o f f s e t f r o m t h e s t a r t o f t h e p a t t e r n , a n d t h e l o n g e s t s t r i n g t h a t m u s t o c c u r a t a f l o a t i n g o f f s e t f r o m t h e s t a r t o f t h e p a t t e r n . U s e d t o d o F a s t - B o y e r - M o o r e s e a r c h e s o n t h e s t r i n g t o f i n d o u t i f i t s w o r t h u s i n g t h e r e g e x e n g i n e a t a l l , a n d i f s o w h e r e i n t h e s t r i n g t o s e a r c h .
# s u b b e g
s u b l e n
s a v e d _ c o p y
s u b o f f
s e t
s u b c o f f s e t
U s e d d u r i n g t h e e x e c u t i o n p h a s e f o r m a n a g i n g s e a r c h a n d r e p l a c e p a t t e r n s , a n d f o r p r o v i d i n g t h e t e x t f o r $ &
, $ 1
e t c . s u b b e g
p o i n t s t o a b u f f e r ( e i t h e r t h e o r i g i n a l s t r i n g , o r a c o p y i n t h e c a s e o f R X _ M A T C H _ C O P I E D ( rx )
) , a n d s u
b l e n
i s t h e l e n g t h o f t h e b u f f e r . T h e R X _ O F F S
s t a r t a n d e n d i n d i c e s i n d e x i n t o t h i s b u f f e r .
I n t h e p r e s e n c e o f t h e R E X E C _ C O P
Y _ S T R
f l a g , b u t w i t h t h e a d d i t i o n o f t h e R E X E C _ C O P Y _ S K I P _ P R E
or R E X
E C _ C O P Y _ S K I P _ P O S T
f l a g s , a n e n g i n e c a n c h o o s e n o t t o c o p y t h e f u l l b u f f e r ( a l t h o u g h i t m u s t s t i l l d o s o i n t h e p r e s e n c e o f R X f _ P
M f _ K E E P C O P Y
o r t h e r e l e v a n t b i t s b e i n g s e t i n P L _ s a w a m p e r s a n d
) . I n t h i s c a s e , i t m a y s e t s u b o f f s
e t
t o i n d i c a t e t h e n u m b e r o f b y t e s f r o m t h e l o g i c a l s t a r t o f t h e b u f f e r t o t h e p h y s i c a l s t a r t ( i . e . s u b b e g
) . I t s h o u l d a l s o s e t s
u b c o f f s e t
, t h e n u m b e r o f c h a r a c t e r s i n t h e o f f s e t . T h e l a t t e r i s n e e d e d t o s u p p o r t @ -
a n d @ +
w h i c h w o r k i n c h a r a c t e r s , n o t b y t e s .
# w r a p p e d
w r a p l e n
S t o r e s t h e s t r i n g q r / /
s t r i n g i f i e s t o . T h e P e r l e n g i n e f o r e x a m p l e s t o r e s ( ? ^ : e e k )
i n t h e c a s e o f q r / e e k /
.
W h e n u s i n g a c u s t o m e n g i n e t h a t d o e s n ' t s u p p o r t t h e ( ? : )
c o n s t r u c t f o r i n l i n e m o d i f i e r s , i t ' s p r o b a b l y b e s t t o h a v e q r / /
s t r i n g i f y t o t h e s u p p l i e d p a t t e r n , n o t e t h a t t h i s w i l l c r e a t e u n d e s i r e d p a t t e r n s i n c a s e s s u c h a s :
my $x = qr/a|b/; # "a|b"
my $y = qr/c/i; # "c"
my $z = qr/$x$y/; # "a|bc"
T h e r e ' s n o s o l u t i o n f o r t h i s p r o b l e m o t h e r t h a n m a k i n g t h e c u s t o m e n g i n e u n d e r s t a n d a c o n s t r u c t l i k e ( ? : )
.
# s e e n _ e v a l s
T h i s s t o r e s t h e n u m b e r o f e v a l g r o u p s i n t h e p a t t e r n . T h i s i s u s e d f o r s e c u r i t y p u r p o s e s w h e n e m b e d d i n g c o m p i l e d r e g e x e s i n t o l a r g e r p a t t e r n s w i t h q r / /
.
# r e f c n t
T h e n u m b e r o f t i m e s t h e s t r u c t u r e i s r e f e r e n c e d . W h e n t h i s f a l l s t o 0 , t h e r e g e x p i s a u t o m a t i c a l l y f r e e d b y a c a l l t o p r e g f r e e . T h i s s h o u l d b e s e t t o 1 i n e a c h e n g i n e ' s " c o m p " r o u t i n e .
# H I S T O R Y
O r i g i n a l l y p a r t o f p e r l r e g u t s .
# A U T H O R S
O r i g i n a l l y w r i t t e n b y Y v e s O r t o n , e x p a n d e d b y Æ v a r A r n f j ö r ð B j a r m a s o n .
# L I C E N S E
C o p y r i g h t 2 0 0 6 Y v e s O r t o n a n d 2 0 0 7 Æ v a r A r n f j ö r ð B j a r m a s o n .
T h i s p r o g r a m i s f r e e s o f t w a r e ; y o u c a n r e d i s t r i b u t e i t a n d / o r m o d i f y i t u n d e r t h e s a m e t e r m s a s P e r l i t s e l f .
P e r l d o c B r o w s e r i s m a i n t a i n e d b y D a n B o o k ( D B O O K ) . P l e a s e c o n t a c t h i m v i a t h e G i t H u b i s s u e t r a c k e r or e m a i l r e g a r d i n g a n y i s s u e s w i t h t h e s i t e i t s e l f , s e a r c h , o r r e n d e r i n g o f d o c u m e n t a t i o n .
T h e P e r l d o c u m e n t a t i o n i s m a i n t a i n e d b y t h e P e r l 5 P o r t e r s i n t h e d e v e l o p m e n t o f P e r l . P l e a s e c o n t a c t t h e m v i a t h e P e r l i s s u e t r a c k e r , t h e m a i l i n g l i s t , o r I R C t o r e p o r t a n y i s s u e s w i t h t h e c o n t e n t s o r f o r m a t o f t h e d o c u m e n t a t i o n .