I nte rna t io na l J o urna l o f   E lect rica l a nd   Co m p ut er   E ng in ee ring   ( I J E CE )   Vo l.   9 ,   No .   4 ,  A u g u s t   201 9 ,   p p .   3 1 8 5 ~3 1 9 3   I SS N:  2 0 8 8 - 8708 ,  DOI : 1 0 . 1 1 5 9 1 / i j ec e . v9 i 4 . p p 3 1 8 5 - 3193          3185       J o ur na l ho m ep a g e :  h ttp : //ia e s co r e . co m/ jo u r n a ls /in d ex . p h p / I JE C E   A  regex cri t eria  api to co m ple te  the  po w er   o f  regu la r express io ns eng ine       B o ulcha ho ub   H a s s a n,  Ra chi q A m ina ,   L a brij i A m ine,  L a brij i El ho u s s i ne,   M o ha m ed  Azo ua zi   De p a rtme n t  o f   M a th e m a ti c s a n d   Co m p u ter S c ien c e ,   F a c u lt y   o f   S c ien c e s Be n   M ’S IK,  M o ro c c o       Art icle  I nfo     AB ST RAC T   A r ticle  his to r y:   R ec eiv ed   Au g   21 ,   2 0 1 8   R ev i s ed   Mar   2 1 ,   2 0 1 9   A cc ep ted   A p r   4 ,   2 0 1 9       Re g u lar  e x p re ss io n s  a re   h e a v il y   u se d   in   th e   f ield   o f  c o m p u ter  p ro g ra m m in g .   T h e y   a r e   k n o w n   b y   th e ir  stre n g th   to   se a rc h   o r  re p lac e   p a rts  o f   strin g s  a c c o rd in g   t o   a   g iv e n   stru c tu re   (m a il s,  p h o n e ,   n u m b e rs,  e tc.).   Cu rre n tl y   re g u lar  e x p re ss io n s  a re   o n ly   u se d   t o   se a rc h   f o r  so m e   p a tt e rn s  o r  to   m a k e   so m e   su b stit u ti o n s  in   stri n g s.  Ho w e v e r,   th e   n e e d   m a y   b e   w id e r   th a n   th a t  w h e n   it   c o m e s  to   o r d e r  t h e   re su l ts  o f   a   re g u lar  e x p re ss io n   o r  to   g ro u p   t h e m   a c c o rd in g   to   so m e   c rit e ria.  De v e lo p e rs  a re   a l w a y s  c a ll e d   to   a n a ly z e   th e   re su lt s  o f   a   re g u lar  e x p re ss io n   b y   d o in g   so m e   r e strictio n s  su c h   a s  (e q u a l,   n o t  e q u a l,   b e tw e e n )  o r  so m e   p ro jec ti o n s  li k e   (m a x i m u m ,   a v e ra g e ,   g ro u p i n g   b y )  o r  so r ts.  Un f o rtu n a tely ,   to   d o   th e se   trea tm e n ts,  th e   d e v e lo p e r  m u st  im p le m e n t  h is  o w n   a lg o rit h m s  w h ich   c o st  h im   a   re m a rk a b le  e ff o rt  a n d   a   w a ste   o f   ti m e .   W e   p ro p o se   in   th is   p a p e r  a n   A P I  c a ll e d   Re g e x Crit e ria  in sp ired   f ro m   Hib e rn a te  Crit e ria  to   su p p o r t  d e v e lo p e r  w h il e   a n a ly z in g   th e   re su lt s  o f   a   re g u lar ex p re ss io n .   K ey w o r d s :   C r iter ia  A P I     Fin ite  a u to m ata   P r o g r am m i n g   A P I   R eg u lar   ex p r es s io n   Co p y rig h t  ©   2 0 1 9   In stit u te o f  A d v a n c e d   E n g i n e e rin g   a n d   S c ien c e .    Al l  rig h ts re se rv e d .   C o r r e s p o nd ing   A uth o r :   B o u lch ah o u b   Has s a n ,   Dep ar t m en t o f   Ma th e m at ics a n d   C o m p u ter   Scien ce ,   Facu lt y   o f   Sc ien ce s   B en   M’ SI K,   C asab lan ca ,   Mo r o cc o .   E m ail:  h b o u lc h ah o u b @ g m a il. co m       1.   I NT RO D UCT I O N     R eg u lar   e x p r ess io n s   co n s i s t o f   a  s et   o f   c h ar ac ter s   a n d   s y m b o ls   u s ed   to   m atc h   o n e   o r   m o r e  p atter n s   i n   s tr in g s   o r   f ile s .   T h e  I T   ex p er ts   g i v e  t h e m   a  g r ea t  i m p o r ta n ce   d u e  to   th eir   s tr o n g   u tili t y   s u ch   as  u s er   d ata   v alid atio n ,   n et w o r k   d ata  f ilt er in g ,   d ata  ex tr ac tio n ,   in tr u s io n   d etec tio n   etc.   I n   th e  w o r ld   o f   co m p u ter   p r o g r am m i n g ,   m a s ter in g   r eg u lar   ex p r ess io n s   is   a  p o w er f u l  to o l  th at  ca n   h elp   to   cr ea te  p r o g r a m s   ea s il y   an d   q u ick l y .   I t   is   clea r   t h at  a   p r o p er ly   d ef i n ed   r eg u lar   ex p r ess io n   ca n   r ep lace   m u ltip le  l in e s   o f   co d e,   m u ltip l e   lo o p s ,   o r   ev en   an   e n tire   p r o g r a m .   R e g u lar   e x p r ess io n s   ar e   w id el y   u s ed   in   co m p u ter   f ie ld s   an d   esp ec iall y   w h e n   u s i n g   p r o g r a m m i n g   la n g u a g es.   A cc o r d in g   to   t h e  s t u d ies  o f   C h ap m a n   C   a n d   S to lee  KT   [ 1 ] ,   5 0 %  o f   p r o f ess io n al   d ev elo p er s   co m p o s e  r eg u lar   ex p r es s io n s   at   lea s t  o n ce   a  w ee k   a n d   4 2 %  o f   t h e  p r o j ec ts   s tu d ied   co n tain   r eg u lar   ex p r es s io n s .   T h e  in cr ea s i n g   u s e  o f   r eg u lar   ex p r ess io n s   h a s   led   m an y   r ese ar ch er s   to   co n s id er   th e m   as   t h e  d o m ai n   o f   t h eir   w o r k .   W ü s t h o lz  V   [ 2 ]   p r o p o s ed   a  to o l  ca lled   “ E x p lo iter ”  t o   s ec u r e  ap p licatio n s   th at  u s e  r e g u lar   ex p r es s io n s .   C o ch r an   R A   [ 3 ]   o f f er ed   a  to o l c alled   “CR OW DB OO ST ”  to   h elp   d ev elo p er s   f i n d   th e  m o s t  ap p r o p r iate  r eg u lar   e x p r ess io n .   B ar to li  A   [ 4 ]   h as  tr ied   to   r ed u ce   th e  co m p le x it y   o f   cr ea tin g   r eg ex   b y   p r o p o s in g   a n   au to m a tic  g e n e r atio n .   Sp is h a k   E   [ 5 ]   p r o p o s ed   to   v alid ates  r eg u lar   ex p r ess io n   s y n tax   a n d   ca p tu r in g   g r o u p   at  co m p ile  ti m e  in s tead   o f   at  r u n   ti m e.   Un f o r tu n atel y ,   r eg u lar   e x p r es s io n s   o n l y   f i n d   s p ec i f ic  p iece s   i n   a  s tr in g   a n d   n ev er   ac t  o n   th e   f o u n d   v alu e s .   Fo r   e x a m p le,   u s in g   o n l y   r e g u lar   e x p r ess io n s ,   w e  ca n   n o t  ca lc u late  th e   av er a g e,   t h e  m ax ,   o r   th e  m i n   o f   d ig its   f o u n d ,   w e  ca n   n o t  c o m p ar e  t h e  r es u lt s   f o u n d ,   w e  ca n   n o t  d o   f ilter s ,   w e  ca n   n o t  d o   s o r ti n g .   So m e  s y m b o ls   m u s t  b e  ad d ed   to   th e  d ictio n ar y   o f   s y m b o ls   to   p er f o r m   t h ese  t ask s   au to m atica l l y .   T o d ay ,   to   i m p le m e n t  t h is   t y p e  o f   n ee d s ,   d ev elo p er s   m u s t  u s e  b o th   r eg u lar   ex p r ess io n s   an d   a  p r o g r am m i n g   Evaluation Warning : The document was created with Spire.PDF for Python.
                      I SS N :   2 0 8 8 - 8708   I n t J   E lec  &   C o m p   E n g ,   Vo l.  9 ,   No .   4 ,  A u g u s t 2 0 1 9   :   3 1 8 5   -   3193   3186   lan g u a g e  an d   m u s t  cr ea te  s e v er al  lin e s   o f   co d e.   I t  is   clea r ,   th en ,   th a t  th e  c u r r en t  i m p l e m en tatio n   o f   th e s e   n ee d s   w i ll  ta k es  a   lo t  o f   ti m e   f o r   d ev elo p er s ,   it  w ill  g e n er ate  s e v er al  u s eles s   li n es   o f   co d e,   an d   u s u all y   w e   f o u n d   a  co m p letel y   d i f f er en t c o d e  in s tr u ct io n s   to   s o lv e  t h e  s a m e  p r o b lem .   Dev elo p er s   k n o w   t h at  u s i n g   an   alr ea d y   test ed   A P I   o r   f r am e w o r k   g r ea tl y   m i n i m izes  t h e  r i s k   o f   b u g s   an d   i m p r o v es  t h e  r ea d ab ilit y ,   th e  q u alit y   an d   t h e  h o m o g e n ei t y   o f   p r o g r a m s .   I n   th i s   p ap er ,   w e  p r o p o s e  an   A P I   ca lled   R eg e x   C r iter ia  to   s i m p lify ,   s ta n d ar d ize,   r ed u ce   th e  p r o g r a m m in g   li n es  u s ed   to   co m p lete  t h e  tas k   o f   a  r eg u lar   e x p r ess io n .   W e  ar e  i n s p ir ed   b y   t h e  s u cc es s   o f   t h e   Hib er n ate  C r iter ia  A P I   [ 6 - 8 ]   to   s tan d ar d ize   all   ag g r e g atio n s ,   tr a n s f o r m atio n s ,   r ed u ctio n s ,   r estrictio n s   an d   all  p r o j ec tio n s   th a t  d ev elo p er s   m u s t  i m p le m e n t   w h ile  u s i n g   a  r eg u lar   ex p r ess i o n .   A l l  p r o g r a m m i n g   la n g u a g es  h a v e  A P I s   f o r   p r o ce s s in g   r eg u lar   e x p r ess io n s   [ 5,   9] ,   b u t  n o   A P I   h as  p r o v id ed   f o r   th e  alr ea d y   m en t io n ed   p r o ce s s in g .   Fo r   th i s   r ea s o n ,   s ev er al  r esear ch er s   h av e  d o n e  w o r k   to   co m p lete  th e  lack   o f   A P I s   cu r r en tl y   o f f er ed   b y   p r o g r am m in g   l a n g u a g es.   Sp is h a k   E   p r o p o s ed   an   an n o tatio n - b ased   A P I   to   h elp   t h e  d ev elo p er   f in d   t h e  er r o r s   o f   r eg u lar   e x p r ess io n s   d u r in g   th e  co m p ilatio n   p h ase   o f   a  p r o g r am   [ 1 0 ] .   Oth er   w o r k s   ai m ed   at  h elp in g   th e  d e v el o p er   to   s im p li f y ,   v alid ate  o r   au to m atica ll y   g e n er ate  r eg u lar   ex p r ess io n s   [2 - 4] .   A ll  f ea t u r es  b u il t  in to   o u r   R eg e x   C r iter ia  A P I   w il l b e  illu s tr ate d   b y   e x a m p les   i m p le m e n ted   u s i n g   t h e  J av a  l an g u a g e  s y n ta x .   T h is   p ap er   is   o r g an ized   as  f o llo w s .   Sectio n   2   tell s   ab o u t  t h e  h i s to r y   o f   r e g u lar   ex p r ess i o n   an d   its   s y m b o ls .   Sectio n   3   p r esen ts   t w o   p r o g r a m s   u s i n g   t h e  r eg u la r   ex p r ess io n s .   A s   f o r   s ec tio n   4 ,   it  talk s   ab o u t  th e  li m ita tio n s   o f   cu r r en t  A P I   d e alin g   w ith   t h e  r eg u lar   ex p r ess io n s .   R e lated   w o r k s   ar e  illu s tr ated   at  Sectio n   5 .   Sectio n   6   b r ief l y   d escr ib e  s o m e  f ea tu r es  o f   R e g e x   C r iter ia   A P I .   T h e  last   s ec tio n   co n ta i n s   f i n al  co n cl u s io n s   an d   p o in ts   to   f u r th er   w o r k .       2.   T H E   R E G UL A R  E XP R E S S I O N   A   r e g u lar   ex p r ess io n   i s   a  s tr i n g   o f   te x t  t h at  d e f in e s   t h e  f o r m at  o f   a   s et  o f   s tr i n g s   ( e m a il  f o r m a t,   p h o n e  n u m b er   f o r m at,   I P   ad d r ess   f o r m at,   etc. ) .   R eg u lar   e x p r ess io n s   ar e  u s ef u l   f o r   f i n d in g   p atter n s   i n   s tr i n g s   an d   p o s s ib l y   r ep lacin g   th e m   w it h   a n o th er   p atter n .   Si n ce   " r eg u lar   e x p r ess io n s "   is   a  m o u t h f u l,  w e  w il l  u s u all y   u s e  t h e  ter m   ab b r ev iated   " r eg ex " .   I n   th e  n ex t  s ec tio n   w e  will  b r ief l y   d is c u s s   th e  s to r y   b e h in d   t h e  p o p u lar it y   o f   r eg ex .     2 . 1 .   Reg ula r  ex pres s io n hi s t o ry   T h e  id ea   o f   r eg u lar   ex p r ess i o n s   w as  d is co v er ed   b y   W ar r en   Mc C u llo ch   a n d   W alter   P itts   in   1 9 4 3   th r o u g h   t h e  p u b lica tio n   o f   th e ir   ar ticle  " A  lo g ica l  ca lc u latio n   o f   id ea s   i m m an e n t   to   n er v o u s   ac ti v it y "   i n   th e   B u lleti n   o f   Ma t h e m a tical  b io p h y s ics  [ 1 1 ] .   I n   1 9 5 6 ,   th e  m ath e m aticia n   S tep h e n   Klee n e   d ev elo p ed   a  m o d el   th at  p r ese n ts   a  s i m p le  al g eb r a  in   t h e  ar ticle   " R ep r esen tati o n   o f   ev e n t s   i n   n et w o r k s   o f   n er v es  a n d   f i n ite   au to m ata"   [1 2] .   A t  th at  ti m e  th e  ter m s   r eg u lar   s et s   an d   r eg u lar   ex p r es s io n s   w e r e  b o r n .   I n   1 9 6 8 ,   Ken   T h o m p s o n   p u b lis h ed   t h e   ar ticle  " R eg u lar   E x p r ess io n   Sear ch   Alg o r it h m "   [ 1 2 ,   13]   to   d escr ib e  a  r eg u lar   ex p r e s s io n   co m p iler .   He  w as   b ased   o n   th e  Klee n e  n o tatio n   to   cr ea te  th e  QE D  ed ito r   to   h elp   u s er s   s ea r ch   th r o u g h   te x t  f ile s .   T h e  w o r k   o f   Ken   T h o m p s o n   h a s   m ad e  i t  p o s s ib le  to   d o   g lo b al  s ea r ch   in   U n ix   f ile s   u s i n g   th e  \ Glo b al \ R e g e x \ P r in t  ( GR E P )   co m m a n d s ,   w h ich   ar e  c u r r en tl y   w ell  k n o w n .   Fro m   th e  8 0 s ,   r eg u lar   ex p r ess io n s   b eg a n   to   g ai n   g r e at  p o p u lar it y   in   t h e  w o r ld   o f   co m p u ter   p r o g r a m m i n g .   T h an k s   to   th e  m u ltip le   w o r k s   o f   He n r y   Sp en ce r ,   P er l  lan g u a g e  is   co n s id er ed   a m o n g   th e  f ir s t  lan g u ag e s   th at  h av e  i n v e s ted   a  lo t  in   th e   f ield   o f   r eg u lar   ex p r es s io n s .     2 . 2 .   Reg ula r  ex pres s io n sy m bo l s   Sev er al  s p ec ial  c h ar ac ter s   ar e  u s ed   to   b u ild   a  r eg e x ,   P au l  B o er s m a  a n d   Dav id   W ee n i n k   g a v e  a  g o o d   ex p lan atio n   to   th e s e  s y m b o l s   w it h   s i m p le  e x a m p les  to   f ac ili tate  u n d er s tan d i n g   [ 1 4 ] .   I n   th e   f o llo w in g   T ab le  1  w e  s u m m ar ize  th e  m ea n in g   o f   ea ch   ch ar ac ter .     2 . 3 .   Reg ula r  ex pres s io n e x a m p le s   E x p r ess io n s   ar e  n o w   av a ilab le  o n   th e  in ter n et.   T h e y   ar e  ev en   in te g r ated   w ith   all  d ev elo p m e n t   f r a m e w o r k s   to   h elp   d ev elo p er s   v alid ate  d ata  en ter ed   b y   u s er s   an d   also   to   h elp   th e m   e x tr ac t  d ata  ac co r d in g   to   th e  co n tex t  o f   t h eir   w o r k .   W e   g i v e  b elo w   s o m e   ex a m p les   with   th e   n ec e s s ar y   e x p lan atio n s   in   o r d er   to   in itia te   th e  g lo b al  s tr u ct u r e  o f   a  r e g u l ar   ex p r ess io n .   I t  i s   i m p o r ta n t  t o   n o te  th at  t h e  w o r ld   o f   r eg u l ar   ex p r ess io n   i s   n o t  to tall y   ac cu r ate.   T h u s ,   th e  e x a m p les  b elo w   ca n   ad m it  s e v er al  r eg u lar   e x p r ess io n s   ac co r d in g   to   th e  s i m p lici t y   an d   p r ec is io n   d esire d .   A l w a y s   th e  s y m b o l  ( ^)   d en o tes t h e  b eg in n i n g   o f   a  s tr i n g   a n d   ( $ )   d en o tes it s   en d .           Evaluation Warning : The document was created with Spire.PDF for Python.
I n t J   E lec  &   C o m p   E n g     I SS N:  2 0 8 8 - 8708       A   r eg ex crit eria   a p i to   co mp let e  th e  p o w er o f reg u la r   ex p r ess io n s   en g in e   ( B o u lch a h o u b   Ha s s a n )   3187   T ab l e  1 .   R eg u lar   ex p r ess io n   s y m b o ls     T h e   me a n i n g   Ex a mp l e s   \   G i v e s sp e c i a l   me a n i n g   t o   t h e   c h a r a c t e r   f o l l o w i n g   i t   \ w   a   w o r d .   \ n   a   n e w   l i n e . \ +   d i s a b l e   t h e   c a r a c t e r   +   ^   S t a r t   o f   t h e   s t r i n g ,   o r   t h e   n e g a t i o n   sy mb o l   ^ c   mat c h e s c   a t   t h e   s t a r t   o f   t h e   s t r i n g .   [ ^ 0 - 9 ]   ma t c h e s a n y   n o n   d i g i t   $   En d   o f   t h e   st r i n g   e $   mat c h e s “ e ”   a t   t h e   e n d   o f   a   l i n e   { }   A  R a n g e   q u a n t i f i e r   b {2 , 3 }   ma t c h e s “ b b ”   o r   “ b b b ”   [   ]   D e f i n e s a   c h a r a c t e r   c l a ss   t o   m a t c h   a   s i n g l e   c h a r a c t e r   [a - c ]   ma t c h e s “ a ” ,   “ b ”   o r   “ c ”   (   )   U se d   f o r   g r o u p i n g   c h a r a c t e r s   ( e e ) \ 1   mat c h e s “ e e e e ”   .   a n y   c h a r a c t e r   e x c e p t   t h e   n e w l i n e   s y mb o l   . b   t w o   c o n se c u t i v e   c h a r a c t e r s w h e r e   t h e   l a st   o n e   i s “ b ”   .* \ . p d f $   a l l   st r i n g s  t h a t   e n d   i n   " . p d f "   *   Z e r o   o r   mo r e   q u a n t i f i e r   ^ . * $   ma t c h e s a n   e n t i r e   l i n e   +   O n e   o r   mo r e   q u a n t i f i e r   \ d +   o n e   o r   mo r e   d i g i t s   \ w +   o n e   o r   mo r e   w o r d s   ?   Z e r o   o r   o n e   q u a n t i f i e r .   ?   i s A l so   u se d   i n   sp e c i a l   c o n st r u c t s w i t h   p a r e n t h e se s.   T h e   same   a s {0 , 1 }   a b ? c   l o o k s fo r   “ a ”   f o l l o w e d   b y   z e r o   o r   o n e   “ b ” ,   a n d   t h e n   “ c ”   |   S e r i e s o f   a l t e r n a t i v e s   " ( a | b | c ) b "   mat c h e s "a b "   o r   " b b "   o r   " c b "   < >   L e f t   o r   r i g h t   w o r d   b o u n d a r y .   \ b   c a n   b e   u se d   l i k e   a   sh o r t e r   w a y   f o r   mat c h i n g   b o u n d a r i e s.   [ [ : < : ] ] c a t   m a t c h e s “ c a t ” i n   “ c a t o m ”   c a t [ [ : > : ] ]   m a t c h e s “ c a t ” i n   t o mc a t   [ [ : < : ] ] c a t [ [ : > : ] ]   ma t c h e s o n l y   “ c a t ”   -   I n d i c a t e s a   r a n g e   i n   a   c h a r a c t e r   c l a ss   [A - Z ]   mat c h e s a n y   u p p e r c a se   c h a r a c t e r   &   S u b s t i t u t e   c o mp l e t e   ma t c h   R e p l a c i n g   \ d +   w i t h   [ \ & ]   i n   1 a 2 b   y i e l d s [1 ] a [ 2 ] b       2 . 3 . 1 .   E m a il  re g ex   E m ail  v alid atio n ,   h as  b ee n   t h e  s u b j ec t  o f   s ev er al  R eg e x   b ec au s e  o f   t h e  co n ti n u o u s   s ea r ch   f o r   s i m p lic it y   a n d   p r ec is io n .   T o   g iv e   in tr o d u cto r y   e x p lan a tio n s ,   let's tak e  t h e  f o llo w i n g   E m a il’s   ex p r ess io n .     ^[ _ A - Za - z0 - 9 - \ \ +]   +  ( \ \ . [ _A - Za - z0 - 9 - ]   +)   * @ [ A - Za - z0 - 9 - ]   +   ( \ \ . [ A - Za - z0 - 9 ]   +)   * ( \ \ . [ A - Za - z]   { 2, })   $     T h is   r eg ex   is   d i v id ed   in   T ab le  2   in to   s ev er al  p ar ts   to   g i v e  th e   n ec ess ar y   ex p l a n atio n s .       T ab le  2 .   E m ail   r eg u lar   ex p r es s io n   d escr ip tio n   Emai l   R e g u l a r   Ex p r e ssi o n   D e scri p t i o n   [ _ A - Za - z0 - 9 - \ \ + ]   +   A n   Emai l   m u st   st a r t   w i t h   a   c h a r a c t e r   i n   t h e   b r a c k e t   [   ]   a n d   i t   mu st   c o n t a i n s  o n e   o r   mo r e   c h a r a c t e r s (+)   ( \ \ . [ _A - Za - z0 - 9 - ]   + )   *       ( →   S t a r t i n g   t h e   f i r st   g r o u p     \ \ .   [ _A - Za - z0 - 9 - ]   +   →  F o l l o w   b y   a   d o t   " . "   a n d   c h a r a c t e r   i n   t h e   b r a c k e t   [   ] ,   mu st   c o n t a i n s  o n e   o r   mo r e   c h a r a c t e r s (+)   )   *   →  E n d i n g   t h e   f i r st   g r o u p ,   t h i s g r o u p   i s   o p t i o n a l   ( * )   @ [ A - Za - z0 - 9 - ]   +       @   →   A n   Ema i l   mu s t   c o n t a i n   a   " @ "   s y mb o l   [A - Za - z0 - 9 - ]   +   →   F o l l o w   b y   c h a r a c t e r   i n   t h e   b r a c k e t   [   ] ,   m u s t   c o n t a i n s o n e   o r   mo r e   c h a r a c t e r s (+)   ( \ \ . [ A - Za - z0 - 9 ]   + )   *     ( →   S t a r t i n g   t h e   se c o n d   g r o u p     \ \ .   [ A - Za - z0 - 9 ]   +   →  F o l l o w   b y   a   d o t   " . "   a n d   c h a r a c t e r   i n   t h e   b r a c k e t   [   ] ,   mu st   c o n t a i n s   o n e   o r   mo r e   c h a r a c t e r s (+)   )   *   →  E n d i n g   t h e   se c o n d   g r o u p ,   t h i s   g r o u p   i s o p t i o n a l   ( * )   ( \ \ . [ A - Za - z ]   { 2 , })     (→   S t a r t i n g   t h e   t h i r d   g r o u p   \ \ . [ A - Za - z ]   { 2, }:   F o l l o w   b y   a   d o t   " . "   a n d   c h a r a c t e r   i n   t h e   b r a c k e t   [   ] ,   w i t h   mi n i m u m l e n g t h   o f   2   )   →  E n d i n g   t h e   t h i r d   g r o u p       2 . 3 . 2 .   P ho ne  nu m b er   r eg ex   An o th er   ca s e  o f   u s i n g   t h e  r eg ex   i s   t h e  v alid atio n   o f   t h e  p h o n e  n u m b er   f o r m a ts .   Ag ai n ,   i d en tical  to   th e  ca s e  o f   e m ail,   s e v er al  ex p r ess io n s   ar e  d esig n ed   to   ch ec k   th e  p h o n e  n u m b er s   a n d   also   to   r ep lace   th e m   w it h   th e  co r r ec t  f o r m at  d ef i n ed   b y   th e  r eg e x .   I m a g in e  i n   t h is   e x a m p le  t h at  w e  w a n t  to   d eter m i n e  if   a  u s er   h a s   en ter ed   a  No r th   Am er ican   p h o n e  n u m b er   a n d   w e  w a n t   to   cr ea te  a  r e g ex   th a t  d et ec ts   t h at  n u m b er s :   1 2 3 5 5 6 6 8 8 0 ,   1 2 3 - 5 5 6 - 6 8 8 0 ,   1 2 3 . 5 5 6 . 6 8 8 0 ,   1 2 3   5 5 6   6 8 8 0 ,   ( 1 2 3 )   5 5 6   6 8 8 0   ar e  v alid   an d   3 5 5 6 6 8 8 0 ,   2 3 . 5 5 6 . 6 8 8 0   a r e  in v alid .   A   r e g ex   p r o p o s itio n   m a y   lo o k   l ik e  t h is .     ^ \   ( ?   ( [0 - 9 ] {3 } )   \ ) ?   [ - .  ] ?   ( [0 - 9 ] {3 })   [ - .  ] ?   ( [0 - 9 ] {4 })   $     T h is   r eg u lar   e x p r ess io n   ch ec k s   i f   a   n u m b er   co n tai n s   ex ac t l y   th r ee   g r o u p s   o f   d i g it s .   A  f ir s t   g r o u p   o f   ex ac tl y   3   d ig its   th at   ca n   p o s s i b ly   b e  s u r r o u n d ed   b y   p ar en t h esis ,   a  s ec o n d   g r o u p   o f   ex ac t l y   3   d ig its   f o llo w ed   b y   a  ch o ice  o f   t h r ee   s ep ar ato r s   ( h y p h e n ,   p o in t  o r   s p ac e)   a n d   a  last   g r o u p   o f   ex ac tl y   4   d ig it s   f o llo w ed   al s o   b y     a  ch o ice  o f   th r ee   s ep ar ato r s   ( h y p h e n ,   p o in t  o r   s p ac e) .   Mo r e  ex p lan ati o n s   f o r   th is   e x p r ess io n   ar e  g i v en   i n     T ab le  3 .   Evaluation Warning : The document was created with Spire.PDF for Python.
                      I SS N :   2 0 8 8 - 8708   I n t J   E lec  &   C o m p   E n g ,   Vo l.  9 ,   No .   4 ,  A u g u s t 2 0 1 9   :   3 1 8 5   -   3193   3188   T ab le  3 .   P h o n e  r eg u lar   e x p r ess io n   d escr ip tio n   P h o n e   R e g u l a r   Ex p r e ssi o n   D e scri p t i o n   \ (?   \   ( →   M a t c h   a   l i t e r a l   " ( “ . ?   →  z e r o   a n d   o n e   t i me .   ( [ 0 - 9 ] {3 })   ( →   S t a r t   c a p t u r i n g   g r o u p   1 .   [ 0 - 9]   M a t c h   a   d i g i t .   {3 }   Ex a c t l y   t h r e e   t i me s.   )   →  E n d   c a p t u r i n g   g r o u p   1 .   \ )?   \ )   →  M a t c h   a   l i t e r a l   " ) " .?   →  z e r o   a n d   o n e   t i me .   [ - .   ] ?   M a t c h   d o t ,   h y p h e n   o r   a   s p a c e .?   →  z e r o   a n d   o n e   t i me .     ( [ 0 - 9 ] {3 })     ( →   S t a r t   c a p t u r i n g   g r o u p   2 .   [ 0 - 9]   →  M a t c h   a   d i g i t .   {3 }   →   e x a c t l y   t h r e e   t i me s .)   →  E n d   c a p t u r i n g   g r o u p   2 .   [ - .   ] ?   M a t c h   d o t ,   h y p h e n   o r   a   s p a c e .?   →  z e r o   a n d   o n e   t i me .     ( [ 0 - 9 ] {4 })   ( →   S t a r t   c a p t u r i n g   g r o u p   3 .   [ 0 - 9]   →  M a t c h   a   d i g i t .   {4 }   →   e x a c t l y   t h r e e   t i me s .)   →  E n d   c a p t u r i n g   g r o u p   3 .       2 . 3 . 3 .   URL  re g ex   T h e  UR L   v alid atio n   is   an o th er   h ig h l y   u s ed   ex a m p le  i n   th e  h ttp   co m m u n ica tio n   p r o to co l  w h ic h   is   also   b ased   o n   r eg ex .   T h e  ex p r ess io n   e x p lain ed   i n   T ab le  4   v e r if ies  w h et h er   an   U R L   i s   v a lid   o r   n o t.     /^( h ttp s ? : \ / \ /) ? ( [ \ da - z \ . - ] +) \ . ( [ a - z \ . ] {2 , 6 }) ( [ \ / \ w  \ . - ] * ) * \ /? $ /       T ab le  4 .   UR L   r eg u lar   ex p r ess i o n   d escr ip tio n   UR L   R e g u l a r   Ex p r e ssi o n   D e scri p t i o n   ( h t t p s? : \ / \ / ) ?   T h e   S t r i n g   " h t t p : / / "   o r   " h t t p s: / / "   a t   t h e   b e g i n n i n g .   T h i s   S t r i n g   i s o p t i o n a l   ( ? ) .   ([ \ da - z \   . - ] + )     N u mb e r s ( \ d ) ,   L e t t e r s (a - z ) ,   D o t s (.) o r   H y p h e n s ( - )   o n e   o r   mo r e   t i me   ( + )   \ . ( [ a - z \ . ] {2 , 6 })   A   d o t   f o l l o w e d   b y   t w o   t o   si x   l e t t e r s o r   d o t s .   ( [ / \ w  \ . - ] * ) * / ? :     Z e r o   o r   mo r e   L e t t e r s,  N u mb e r s,  U n d e r sco r e s,  d o t s o r   h y p h e n s w i t h   a n   o p t i o n a l   f o r w a r d   sl a sh .       3.   SO M E   SI M P L E   P RO G RA M S USI NG   RE G E X   I m ag i n e  t h at  w e  as k   a  d ev elo p er   to   ca lcu late  th e  av er ag e  o f   th e  ca ll  d u r atio n s   m ad e  ea ch   m o n t h   an d   w e  g i v e  h i m   t h e  d ata  in   a  f i le  as sh o w n   i n   T ab le  5 .       T ab le   5.   T h e  av er ag e  o f   th e  ca ll d u r atio n s   P h o n e   N u mb e r   T o t a l   C a l l   D u r a t i o n   b y   M o n t h   ( T C D . M x )   T C D   M1   T C D   M2   T C D   M3   T C D   M4   T C D   M5   T C D   M6   T C D   M7   T C D   M8   T C D   M9   T C D   M 1 0   1 2 3 5 5 6 6 8 8 0     10     2 0     11   22   34   22   12   40   30   21   1 2 3 4 4 4 6 8 7 8   13   15   10   09   12   30   23   45   12   45   1 2 3 5 5 5 7 0 8 0     13   15   10   09   12   15   22   11   22   33   1 2 3 5 5 1 2 5 5 3   10   11   12   13   13   14   22   43   10   31   1 2 3 5 2 3 5 5 3 1   12   08   12   11   05   22   11   23   11   11   1 2 3 5 4 4 5 5 3 7     09   11   20   09   05   10   21   22   11   09   1 2 3 5 6 6 5 5 3 2     1 1   08   02   21   15   20   11   33   22   11       I f   th e  d e v elo p er   h as  ch o s e n   to   u s e  t h e  r eg e x   in   t h i s   p r o b le m ,   h e  w ill  p r o b ab ly   b u ild   a  r eg ex   t o   r ep r esen t  th e  s tr u ct u r e  o f   an   e n tire   li n e  u s in g   t h e  n a m ed   g r o u p s   to   r ep r esen t  ea ch   co l u m n .   Her e  is   a  p o s s ib le  p r o p o s al  f o r   th is   r e g ex   i f   w e  c o n s id er   [ \ s ]   as sep ar ato r .     \ b (? < p h o n e > \ (? ([ 0 - 9 ] { 3 }) \ )? [ - .   ] ?   ([0 - 9 ] { 3 }) [ - .   ] ? ( [ 0 - 9 ] {4 })) [ \ s]   (? < HM1 > \ d + )[ \ s]   (? < HM2 > \ d + )[ \ s]   (? < HM3 > \ d + )[ \ s]   (? < HM4 > \ d + )[ \ s]   (? < HM5 > \ d + )[ \ s]   (? < HM6 > \ d + )[ \ s]   (? < HM7 > \ d + )[ \ s]   (? < HM8 > \ d + )[ \ s]   (? < HM9 > \ d + )[ \ s]   (? < HM 10> \ d + ) \ b     Evaluation Warning : The document was created with Spire.PDF for Python.
I n t J   E lec  &   C o m p   E n g     I SS N:  2 0 8 8 - 8708       A   r eg ex crit eria   a p i to   co mp let e  th e  p o w er o f reg u la r   ex p r ess io n s   en g in e   ( B o u lch a h o u b   Ha s s a n )   3189   W e  n o te  t h at   u s i n g   th e   n a m ed   g r o u p   to   r ep r esen t   a  co l u m n   i n   t h i s   f ile   w ill   b e  v er y   u s ef u l   f o r   f in d i n g   th e  v a lu e s   an d   k n o w i n g   th e ir   t y p e.   I t  is   p ar tl y   t h e  o b jectiv e  o f   t h e  d ec lar atio n   o f   a  v ar iab le  in   t h e   p r o g r am m i n g   la n g u a g es.  Fo r   in s ta n ce ,   w e  ca n   ea s i l y   d ed u ce   f r o m   t h e  p r ev io u s   r eg u lar   e x p r ess io n ,   th e  f o llo w i n g   s tate m e n ts .     \ b (? < p h o n e > \ (? ([ 0 - 9 ] { 3 }) \ )? [ - .   ] ?   ([0 - 9 ] { 3 }) [ - .   ] ? ( [ 0 - 9 ] {4 })) [ \ s ]   ⇔   S tri n g   p h o n e ;   (? < HM1 > \ d + )[ \ s]   ⇔   L o n g   HM 1 ;   (? < HM2 > \ d + )[ \ s]   ⇔   L o n g   HM 2 ;   (? < HM3 > \ d + )[ \ s]   ⇔   L o n g   HM 3 ;   (? < HM4 > \ d + )[ \ s]   ⇔   L o n g   HM 4 ;   (? < HM5 > \ d + )[ \ s]   ⇔   L o n g   HM 5 ;   (? < HM6 > \ d + ) \ b  ⇔   L o n g   HM6 ;     T h is   tech n iq u e  w ill  h elp   u s   t o   k n o w   t h e  p o s s ib le  o p er atio n s   r elati n g   to   a  r eg ex   g r o u p .   I t  d o es  n o t   m ak e  s e n s e,   f o r   in s ta n ce ,   to   d o   Ma x   o r   Min   f o r   th e  " p h o n e"   g r o u p   in   o u r   ex a m p le  b ec au s e  its   t y p e  is   a  Strin g .   A   p o s s ib le  p r o g r a m   to   m ee t  t h e  n ee d   il lu s tr ated   in   th i s   e x a m p le  is   g i v e n   i n   T ab le  6   an d   th e  r es u lt s   o b tain ed   ar e  also   s h o w n   i n   T ab le  7 .       T ab le   6 .   P r o g r am   to   ca lcu late  th e  av er a g e  o f   r eg e x ’ s   r es u lts   i mp o r t   j a v a . u t i l . r e g e x . M a t c h e r ;   i mp o r t   j a v a . u t i l . r e g e x . P a t t e r n ;     p u b l i c   c l a ss Pr o g r a m1   {   p u b l i c   st a t i c   v o i d   m a i n ( S t r i n g [ ]   a r g s)   {      S t r i n g   r e g e x   =   " \ \ b ( ? < p h o n e > \ \ ( ? ( [ 0 - 9 ] { 3 }) \ \ ) ? "   +   " [ - .   ] ? ( [ 0 - 9 ] {3 }) [ - .   ] ? ( [ 0 - 9 ] { 4 }) ) [ \ \ s] "     +   " ( ? < H M 1 > \ \ d + ) [ \ \ s] "     +   " ( ? < H M 2 > \ \ d + ) [ \ \ s] "     +   " ( ? < H M 3 > \ \ d + ) [ \ \ s] "   +   " ( ? < H M 4 > \ \ d + ) [ \ \ s] "     +   " ( ? < H M 5 > \ \ d + ) [ \ \ s] "     +   " ( ? < H M 6 > \ \ d + ) \ \ b " ;     P a t t e r n   p   =   P a t t e r n . c o m p i l e ( r e g e x ) ;     i n t   c o u n t   =   0 ;     d o u b l e   su m  =   0 ;     f o r   ( i n t   i   =   1 ;   i   <   7 ;   i + + )   {       f o r   ( S t r i n g   l i n e   :   a r g s)   {        M a t c h e r   m  =   p . m a t c h e r ( l i n e ) ;         w h i l e   ( m.fin d ( ) )   {          s u m   + =   I n t e g e r . p a r seI n t ( m.g r o u p ( " H M "   +   i ) ) ;         c o u n t + + ;       } / /   E n d   w h i l e       } / /   E n d   2 sd   f o r      S y st e m.o u t . p r i n t l n ( " t h e   H M "   +   i   +   "   a v e r a g e   i s : "   +   ( c o u n t   = =   0   ?   0   :   s u m  /   c o u n t ) ) ;     } / /   E n d   1 st   f o r     }/ /   E n d   ma i n   } / /   E n d   C l a ss Pr o g r a m  1       T ab le  7 .   R esu lts   o f   ca lcu lat in g   th e  av er a g e  o f   r eg e x ’ s   r es u lts   t h e   H M 1   a v e r a g e   i s: 1 1 . 1 4 2 8 5 7 1 4 2 8 5 7 1 4 2   t h e   H M 2   a v e r a g e   i s: 1 1 . 8 5 7 1 4 2 8 5 7 1 4 2 8 5 8   t h e   H M 3   a v e r a g e   i s: 1 1 . 5 7 1 4 2 8 5 7 1 4 2 8 5 7 1   t h e   H M 4   a v e r a g e   i s: 1 2 . 0 3 5 7 1 4 2 8 5 7 1 4 2 8 6   t h e   H M 5   a v e r a g e   i s: 1 2 . 3 7 1 4 2 8 5 7 1 4 2 8 5 7 2   t h e   H M 6   a v e r a g e   i s: 1 3 . 2 1 4 2 8 5 7 1 4 2 8 5 7 1 4       An o th er   ex a m p le  ca lled   " W o r d   C o u n t"   w h ich   co u n ts   t h e  n u m b er   o f   o cc u r r en ce s   f o r   ea ch   w o r d   in     a  f ile  s to r ed   in   t h e  Had o o p   HDFS  [ 1 5 ]   is   v er y   e v o k ed   wh en   i t  co m es  to   t h e  p a r allel  p r o ce s s in g   d o n e  b y   Ma p R ed u ce   [ 1 6 ] .   I n   th is   p ap er   an d   as  s h o w n   in   T ab le  8   w e   p ar s e  th e  s tr in g s   w it h o u t  h a v in g   co n ce r n s   ab o u t   p ar allel  p r o ce s s in g .   T h e  u s e  o f   o u r   R e g ex C r iter ia  A P I   in   th e   co n tex t  o f   p ar allel   p r o ce s s in g   w ill  b e  t h e  s u b j ec t   o f   an o th er   p ap er .       Evaluation Warning : The document was created with Spire.PDF for Python.
                      I SS N :   2 0 8 8 - 8708   I n t J   E lec  &   C o m p   E n g ,   Vo l.  9 ,   No .   4 ,  A u g u s t 2 0 1 9   :   3 1 8 5   -   3193   3190   T ab le  8 .   P r o g r am   an d   r es u lts   o f   ca lcu lati n g   o cc u r r en ce s   f o r   e ac h   w o r d   in   a  S t r in g   i mp o r t   j a v a . u t i l . H a sh M a p ;   i mp o r t   j a v a . u t i l . M a p ;   i mp o r t   j a v a . u t i l . r e g e x . M a t c h e r ;   i mp o r t   j a v a . u t i l . r e g e x . P a t t e r n ;   p u b l i c   c l a ss Pr o g r a m2   {     p u b l i c   st a t i c   v o i d   m a i n ( S t r i n g [ ]   a r g s)   {       M a p < S t r i n g ,   I n t e g e r >   o c c u r r e n c e s =   n e w   H a sh M a p < S t r i n g ,   I n t e g e r > ( ) ;       P a t t e r n   p w o r d   =   P a t t e r n . c o m p i l e ( a r g s[ 0 ] ) ;       S t r i n g   so u r c e   =   a r g s[ 1 ] ;       M a t c h e r   mw o r d   =   p w o r d . mat c h e r ( so u r c e ) ;       w h i l e   ( m w o r d . f i n d ( ) )   {         S t r i n g   w o r d   =   mw o r d . g r o u p ( ) ;         i f   ( o c c u r r e n c e s.c o n t a i n sK e y ( w o r d ) )           c o n t i n u e ;         P a t t e r n   p   =   P a t t e r n . c o m p i l e ( w o r d ) ;         M a t c h e r   m =   p . mat c h e r ( so u r c e ) ;         i n t   c o u n t   =   0 ;         w h i l e   ( m.fin d ( ) )   {           c o u n t + + ;         }         o c c u r r e n c e s. p u t ( w o r d ,   c o u n t ) ;       }       S y st e m.o u t . p r i n t l n ( o c c u r r e n c e s) ;     }   }   R e su l t s:   {A = 2 ,   B = 1 ,   C = 3 ,   D = 1 ,   E = 1 ,   F = 2 ,   M = 1 }       E v en   th o u g h   t h ese   t w o   p r o g r a m s   ar e  v er y   s i m p le,   t h e  n u m b er   o f   li n es   t h e y   co n tai n   i s   v er y   h i g h   co m p ar ed   to   th e  task   t h e y   p er f o r m .   I n   ad d itio n   to   th is ,   t h e y   d ep en d   a  lo t  o n   h o w   t h e  d ev elo p er   th in k s .   T o   h av e  a  h o m o g e n eo u s   co d e  u n d er s to o d   b y   ev er y o n e,   th e  d ev elo p er   m u s t  b e  g u id ed   b y   an   A P I   to   w r ite  th e   s a m e   in s tr u c tio n s   f o r   th e  s a m e  p r o b le m .   So m e  l i m i tatio n s   o f   t h e  c u r r en t   A P I s   ar e  d is cu s s ed   i n   t h e   n ex t  s ec tio n .       4.   SO M E   L I M I T AT I O N S O F   CURR E NT   R E G E X  AP I s   A ll   cu r r e n t  p r o g r a m m i n g   la n g u ag e s   h av e   in teg r ated   s o m e  AP I s   to   h an d le  r e g u lar   ex p r ess i o n s   a n d   to   s i m p li f y   t h e  w o r k   o f   d ev elo p er s   an d   esp ec iall y   to   m ak e   t h eir   co d e  s i m p le  a n d   r ea d ab le  [ 1 7 ] .   B u t   u n f o r tu n a tel y ,   t h e  d ev e l o p er   s till   h as  to   m a k e  ef f o r t s   to   d esig n   a n d   i m p le m e n t  m is s i n g   a lg o r it h m s .   As  s h o w n   i n   th e  t w o   p r ev io u s   ex a m p le s ,   to   ca lcu late  t h e  o cc u r r en ce s   o r   th e  a v er ag e  o f   t h e  n u m b er s   f o u n d   i n   a  Strin g ,   t h e  d ev elo p er   m u s t  d esig n   h is   o w n   al g o r ith m   a n d   m u s t  i m p le m e n t  it   in   s e v er al   lin e s   o f   co d e  w it h   p o s s ib le  er r o r s .   I n   ad d itio n ,   n o   A P I   h a s   i n te g r ated   to o ls   to   h elp   t h e  d ev e lo p er   b u ild   h is   r eg u lar   ex p r es s io n s   d esp ite  th e   co m p le x it y   o f   t h i s   tas k .   I n   t h is   w o r k   w e  p r o p o s e  to   s u p p le m e n t  t h e  c u r r en t  A P I s   w it h   h i g h l y   r eq u ested   f u n ctio n s   th a t  ar e  im p le m e n ted   in   a  r ep etitiv e  wa y   in   p r o g r a m s   u s i n g   r eg u lar   ex p r ess io n s .   Mo s t  o f   th e  m e th o d s   p r o p o s ed   in   Sectio n   6   ar e  in s p ir ed   f r o m   H ib er n ate  C r iter ia  A P I   [ 1 8 ]   an d   m en tio n ed   i n   T ab le  9 .   T o   m o tiv ate   th e   u s ef u l n es s   o f   th i s   A P I ,   w e  f ir s t  p r o p o s e  to   s tu d y   t h e  p r ev io u s   w o r k s   a n d   th en   d escr ib e  th e   s tr en g th   o f   R eg e x C r iter ia  A P I   in   p r o ce s s i n g   r eg e x ’ s   r es u lt s   an d   w e  w ill   f o c u s   later   o n   h o w   t h i s   A P I   ca n   a v o id   th e  w ea k n e s s es e n co u n ter ed   b y   d ev elo p er s   w h e n   u s i n g   t h e  r eg ex   i n   p r o g r a m s .       T ab le  9 .   Featu r es a d d ed   to   R e g ex C r iter ia  A P I     C u r r e n t   R e g e x   A P I s   R e g e x   C r i t e r i a   A P I   N a r r o w i n g   t h e   r e su l t   ×   ⎷   O r d e r i n g   t h e   r e su l t s   ×   ⎷   G r o u p i n g   r e su l t s   ×   ⎷   P r o j e c t i o n s   ×   ⎷   A g g r e g a t i o n s   ×   ⎷       5.   RE L AT E D  WO RK S   T h e  r eg u lar   ex p r ess io n   lan g u ag e  h a s   u n d er g o n e  s e v er al  e n h a n ce m en ts   a n d   ex ten s io n s   f r o m   1 9 4 3   u n t il  to d a y .   Sp is h ak   E   [ 1 0 ]   r e m ar k ed   t h at   er r o r s   d u e  to   t h e  s tr u ct u r e  o f   a  r e g ex   i n   a  p r o g r a m   w i ll  n o t  b e  d etec ted   u n til   th e  e x ec u tio n   ti m e.   So ,   h e  p r o p o s ed   to   v alid ate  r eg u lar   e x p r ess io n   s y n tax   a n d   ca p tu r in g   g r o u p   at  co m p ile  ti m e  i n s tead   o f   at   r u n   ti m e.   C h ap m a n   C   a n d   Sto lee  KT   [ 1 ]   h av e  s t u d ied   4 0 0 0   Op en   So u r ce   Evaluation Warning : The document was created with Spire.PDF for Python.
I n t J   E lec  &   C o m p   E n g     I SS N:  2 0 8 8 - 8708       A   r eg ex crit eria   a p i to   co mp let e  th e  p o w er o f reg u la r   ex p r ess io n s   en g in e   ( B o u lch a h o u b   Ha s s a n )   3191   p r o j ec ts   to   m ea s u r e  t h e  u s e  o f   R e g u lar   e x p r ess io n s .   T h ey   s h o w ed   th at  5 0 %  o f   p r o f e s s io n a l  d ev elo p er s   co m p o s e  r eg u lar   ex p r es s io n s   at  least  o n ce   a  w ee k   a n d   th at  4 2 %  o f   th e  p r o j ec ts   s tu d ied   co n tain   r eg u lar   ex p r ess io n s .   T h ese  r esu lt s   i m p ly   a n   u r g e n t  n ee d   f o r   r ef ac to r in g   r eg e x   an d   cr ea tin g   to o ls   to   b etter   s u p p o r t   d ev elo p er s   w h e n   u s i n g   r eg e x .   I t  is   tr u e  t h at  r eg u lar   e x p r ess io n s   h elp   to   i m p le m e n t  s ev er al  u s e  ca s es  i n     a  p r o g r a m ,   b u t  t h eir   u s e   ca n   g iv e  r i s e  to   v u l n er ab ilit y   r is k s .   W ü s t h o lz  V   [ 2 ]   u s ed   a   to o l  ca lled   " E x p lo iter "   to   f i n d   s ec u r it y   v u l n er ab ilit ies  c au s ed   b y   r e g e x   i n   J av a  W eb   ap p licatio n s .   I n   ad d iti o n   to   t h o s e  w o r k s ,   C o ch r an   R A   [ 3 ]   tell s   t h e   s to r y   o f   a  r eg ex   co llectio n   e x p er i m e n t  t o   v alid ate  th e   UR L   s tr u ct u r e  o n   t h e   w eb   [ 1 9 ] .   T h e  lead er   o f   t h is   e x p er i m e n t   s h o w ed   t h at   th e   m aj o r ity   o f   th e  p r o p o s als  d id   n o t   co v er   al l  p o s s ib le  ca s e s   o f   UR L s .   T h u s   C o c h r an   R A   [ 3 ]   o f f er s   a  to o l  ca lled   C R OW DB OOST   to   h elp   d ev elo p er s   f in d   th e  m o s t  ap p r o p r iate  r eg u lar   e x p r ess io n .   A l s o ,   B ar to li  A  [ 4 ]   h as  tr ied   to   r ed u ce   th e  co m p lex it y   o f   cr ea tin g   r e g ex   b y   p r o p o s in g   a n   au to m atic  g en er atio n   b ased   o n   a  s et  o f   ex a m p l es e n ter ed   b y   th e  d ev e lo p er .       6.   F E AT U RE S O F   T H E   P R O P O SE D  “ RE G E X  CRI T E RI A”   AP I     T o   illu s tr ate  s o m e  m e th o d s   o f   th e  A P I   R e g ex   C r iter ia  w e   co n s id er   th e  r eg u lar   ex p r ess io n   w h ic h   r ep r esen ts   th e  p h o n e  n u m b er s   w it h   t h r ee   g r o u p s   " P A R T 1 " ,   "P A R T 2 "   an d   "P A R T 3 "   as f o llo w i n g .     Strin g   r eg e x P h o n e  =  " \ \ b \ \ (?   ( ? < P A R T 1 >[ 0 - 9 ] {3 } ) \ \ ) ? [ - .   ] ?   ( ? < P A R T 2 >[ 0 - 9 ] {3 } ) [ - .   ] ?   ( ? < P A R T 3 >[ 0 - 9 ] {4 } ) \ \ b " ;     T h e  f o llo w i n g   Strin g   is   co n s id er ed   as a   s o u r ce   f o r   d o in g   th e  n ec es s ar y   test s .     Strin g   s o u r ce   =  " 1 2 3 . 3 4 4 . 5 6 7 8   2 3 3 7 6 8 1 2 3 4   d d   3 4 5 - 9 0 8 - 1 2 3 4   f f f   2 0 0 - 908 - 1 2 3 4   2 3 4 5 4 3 5 0 0 0 " ;     T o   u s e  th e  f ea t u r es o f   t h is   A P I ,   w e  m u s t f ir s t c r ea te  a  R eg e x   C r iter ia  o b j ec t.     R eg e x C r i ter ia  r eg ex C r iter ia  =  R eg e x C r i ter ia. cr ea te( r eg ex P h o n e,   s o u r ce ) ;     6 . 1 .     So m e  re s t rict io ns   u s ing   re g ex   cr it er ia   AP I   I n   th e  co d e  s h o w n   i n   t h e  T ab le  10 ,   w e  tr ea t  th e  f o llo w i n g   r estrictio n s   " No t  E q u a l " ,   " E q u a l " ,   ”L ess   Th a n ”,   “ Grea ter Th a n ”,   “ IN ”  u s i n g   R e g ex C r iter ia.       T ab le  10 .   So m e  r estrictio n s   m ad e  b y   r eg e x   cr iter ia   / /   l i s t   o f   e l e m e n t s   m a t c h i n g   t h e   re g e x   w i t h   “ p a rt 1 ”   i s  d i f f e re n t   f r o m   "1 2 3 "   L i st < S t r i n g >   r e su l t = r e g e x C ri t e r i a . a d d ( Re g e x Re s t ri c t i o n s. n e ( "PART 1 " ,   "1 2 3 " ) ) . l i st ( ) ;   / /   l i s t   o f   e l e m e n t s   m a t c h i n g   t h e   re g e x   w i t h   “ p a rt 1 ”   i s e q u a l   t o   " 1 2 3 "   L i st < S t r i n g >   r e su l t = r e g e x C ri t e r i a . a d d ( Re g e x Re s t ri c t i o n s. e q ( "PART 1 " ,   "1 2 3 " ) ) . l i st ( ) ;   / /   l i s t   o f   e l e m e n t s   m a t c h i n g   t h e   re g e x   w i t h   “ p a rt 1 ”   I s  l e ss   t h a n   "1 2 3 "   L i st < S t r i n g >   r e su l t = r e g e x C ri t e r i a . a d d ( Re g e x Re s t ri c t i o n s. l t ( " P ART 1 " ,   "1 2 3 " ) ) . l i st ( ) ;   / /   l i s t   o f   e l e m e n t s   m a t c h i n g   t h e   re g e x   w i t h   “ p a rt 1 ”   I s  g re a t e r  t h a n   "1 2 3 "   L i st < S t r i n g >   r e su l t = r e g e x C ri t e r i a . a d d ( Re g e x Re s t ri c t i o n s. g t ( "PART 1 " ,   "1 2 3 " ) ) . l i st ( ) ;   / /   l i s t   o f   e l e m e n t s   m a t c h i n g   t h e   re g e x   w i t h   “ p a rt 1 ”   I s  e q u a l   t o   "1 2 3 "   o r “ 4 0 0 ”   L i st < S t r i n g >   r e su l t = r e g e x C ri t e r i a . a d d ( Re g e x Re s t ri c t i o n s. i n ( "PART 1 " ,   { " 1 2 3 ", " 4 0 0 " })) . l i st ( ) ;       6 . 2 .     So m e  a g g re g a t io ns   a nd   pro j ec t io ns   us ing   re g ex   cr it er ia   AP I   I n   th e  co d e  s h o w n   in   t h e  T a b le  1 1 ,   w e  tr ea t  th e  f o llo w i n g   ag g r eg atio n s   " Ma ximu m " ,   " A ve r a g e " ,   ”M in i m u m ”,   “ Gro u p in g   b y ”,   “ C o u n tin g ”  u s in g   R e g e x C r it er ia.   I t  is   q u ick l y   r e m ar k ab le   th at  ea ch   p r o g r a m   illu s tr ated   in   s ec tio n   3   ca n   b e  r ep lace d   b y   o n l y   o n e   li n e  as  s h o w n   in   th e   in s tr u c tio n s   n o ted   b y   ( * * * )   in   T ab le  1 1 .                     Evaluation Warning : The document was created with Spire.PDF for Python.
                      I SS N :   2 0 8 8 - 8708   I n t J   E lec  &   C o m p   E n g ,   Vo l.  9 ,   No .   4 ,  A u g u s t 2 0 1 9   :   3 1 8 5   -   3193   3192   T ab le  1 1 .   So m e  ag g r eg atio n s   an d   p r o j ec tio n s   m ad e  b y   r eg e x   cr iter ia  A P I   * * *   / /   C a l c u l a t e   t h e   a v e ra g e   o f   d i g i t s  f o u n d   b y   t h e   r e g e x .   O n l y   d i g i t s   o f   t h e   g ro u p   “ P a rt 1 ”   a re   u s e d   d o u b l e   a v g = re g e x C r i t e ri a . se t R e g e x Pr o j e c t i o n ( R e g e x P ro j e c t i o n s. a v g ( " PA R T 1 " ) ) . v a l u e ( ) ;   / /   Fi n d   t h e   m a x i m u m   o f   d i g i t s  f o u n d   b y   t h e   re g e x .   O n l y   d i g i t s  o f   t h e   g r o u p   “ Pa rt 1 ”   a r e   u se d   d o u b l e   m a x = re g e x C r i t e ri a . s e t R e g e x P ro j e c t i o n ( R e g e x Pro j e c t i o n s. m a x ( " PA RT1 " ) ) . v a l u e ( ) ;   / /   Fi n d   t h e   m i n i m u m   o f   d i g i t s  f o u n d   b y   t h e   re g e x .   O n l y   d i g i t s  o f   t h e   g r o u p   “ Pa rt 1 ”   a r e   u se d   d o u b l e   m i n = re g e x C r i t e ri a . s e t R e g e x P ro j e c t i o n ( R e g e x Pro j e c t i o n s. m i n ( " P AR T 1 " ) ) . v a l u e ( ) ;   / /   C a l c u l a t e s  t h e   s u m   o f   d i g i t s f o u n d   b y   t h e   re g e x .   O n l y   d i g i t s  o f   t h e   g r o u p   “ Pa rt 1 ”   a r e   u se d   d o u b l e   s u m = re g e x C ri t e r i a . se t Re g e x P ro j e c t i o n ( R e g e x Pro j e c t i o n s. s u m ( " PA RT1 " ) ) . v a l u e ( ) ;   * * *   / /   C o u n t   t h e   n u m b e r  o f   o c c u rre n c e s  f o r e a c h   e l e m e n t   f o u n d   b y   t h e   re g e x .   L i st   l i s t   =   r e g e x C ri t e r i a . se t Re g e x Pr o j e c t i o n ( R e g e x Pr o j e c t i o n s. p ro j e c t i o n L i st ( ) . a d d ( Re g e x Pro j e c t i o n s   . c o u n t ( ) ) . a d d ( Re g e x Pr o j e c t i o n s. g ro u p By ( "PART 1 " ) ) ) . l i st ( ) ;   / /   c o u n t   t h e   n u m b e r  o f   e l e m e n t s   f o u n d   b y   t h e   re g e x     i n t   c o u n t = re g e x C r i t e ri a . s e t R e g e x Pro j e c t i o n ( R e g e x Pr o j e c t i o n s.c o u n t ( ) ) . v a l u e ( ) ;   / /   c o u n t   n u m b e r  o f   d i st i n c t   e l e m e n t s   f o u n d   b y   t h e   re g e x     i n t   c o u n t D i s t i n c t = re g e x C r i t e ri a . s e t R e g e x Pro j e c t i o n ( R e g e x Pr o j e c t i o n s.c o u n t D i st i n c t ( ) ) . v a l u e ( ) ;         6 . 3 .     O rder ing   re s ults by   re g ex   cr it er ia   AP I   An o th er   n ee d   th at   d ev elo p e r s   i m p le m e n t   in   a  r ep etiti v e   w a y   co n ce r n s   th e   s o r ti n g   o f   r es u lts   ac co r d in g   to   d if f er e n t  cr iter ia  an d   th e   li m itatio n s   o f   t h e  r es u lts   to   b e  d is p la y ed   to   t h e  f in a l   u s er .   W e  s h o w   i n   th e  T ab le  1 2 ,   h o w   to   d o   s o r tin g   u s in g   R eg e x C r iter ia.         T ab le  1 2 .   A s c  an d   d esc  s o r t  m ad e  b y   r eg e x cr iter ia   / /   Asc .   S o r t   o f   t h e   e l e m e n t s  f o u n d   b y   t h e   r e g e x .   O n l y   d i g i t s  o f   t h e   g r o u p   “ P a rt 1 ”   a re   c o n c e r n e d   L i st < S t r i n g >   o r d e r e d A scR e su l t   =   re g e x C r i t e ri a . a d d O r d e r( R e g e x O r d e r . a s c ( " PA RT1 " ) ) . l i s t ( ) ;   / /   D e sc.   S o r t   o f   t h e   e l e m e n t s  f o u n d   b y   t h e   re g e x .   O n l y   d i g i t s  o f   t h e   g r o u p   “ P a rt 1 ”   a re   c o n c e r n e d   L i st < S t r i n g >   o r d e r e d A scR e su l t   =   re g e x C r i t e ri a . a d d O r d e r( R e g e x O r d e r . d e s c ( " P ART 1 " ) ) . l i st ( ) ;       7.   CO NCLU SI O N    R eg u lar   ex p r ess io n s   ar e  w id el y   u s ed   b y   d ev elo p er s   to   im p le m e n t  t h e  d if f er en t  ca s e s   o f   th ei r   ap p licatio n s .   Fo r   t h is   r ea s o n ,   all  p r o g r a m m i n g   lan g u ag e s   h a v e  i n te g r ated   to o ls   an d   A P I s   t o   g u id e  a n d   s u p p o r t  th e  d ev elo p er   w h e n   h a n d lin g   r eg ex .   U n f o r t u n ate l y ,   t h ese  AP I s   d o   n o t  m an a g e  to   p r o ce s s   th e  r esu lts   o b tain ed   b y   a  r e g ex   to   m a k e,   f o r   e x a m p le,   r estrictio n s ,   p r o j ec tio n s   o r   s o r tin g .   I n   t h is   p ap er ,   w e  p r o p o s ed   an   A P I   ca lled   R eg e x C r i ter ia  in   w h ic h   w e  h a v e  i m p le m e n ted   all  t h e  f ea tu r e s   th at  a  d e v elo p er   ca n   u s e  to   ac t  o n   th e  r es u lt s   o f   a  r eg ex .   W e  b eliev e  t h at  t h is   A P I   w ill  b e  v er y   u s e f u l  i n   t h e  p ar allel  p r o ce s s in g   o f   B i g   Data   an d   esp ec iall y   w h e n   cr ea tin g   Ma p R ed u ce   p r o g r a m s ,   s o   o u r   n ex t  w o r k   w i ll  b e  f o cu s ed   o n   t h is   i s s u e.       RE F E R E NC E S     [1 ]   Ch a p m a n   C,   S to lee   KT . ,   " Ex p lo r in g   re g u lar  e x p re ss io n   u sa g e   a n d   c o n tex t  i n   P y th o n ,"   In :   Pro c e e d i n g s  o f  t h e   2 5 t h   In ter n a t io n a l  S y mp o siu m  o n   S o ft wa re   T e stin g   a n d   A n a lys is  -   IS S T A  2 0 1 6 ,   [ O n li n e ] ,   2 0 1 6 ,   A v a il a b le  f ro m :   h tt p : // d x . d o i. o rg /1 0 . 1 1 4 5 / 2 9 3 1 0 3 7 . 2 9 3 1 0 7 3 .   [2 ]   W ü sth o lz  V ,   Oliv o   O,  He u le  M JH ,   Dill ig   I .,   " S tatic   De te c ti o n   o f   Do S   V u ln e ra b il it ies   in   P r o g ra m s   th a t  Us e   Re g u lar  Ex p re ss io n s ,"   In :  L e c tu re   No tes   i n   Co m p u ter   S c ie n c e ,   2 0 1 7 ,   p p .   3 – 20.   [3 ]   Co c h ra n   RA ,   D’ A n to n i  L ,   L iv sh it s B,   M o ln a r  D,  V e a n e s M . ,   " P r o g ra m   Bo o stin g ,"   ACM   S IGPL AN  No ti c e s ,   v o l.   50 ,  p p .   1 ,   p p .   6 7 7 – 88 ,  2 0 1 5 .   [4 ]   Ba rto li   A ,   Da v a n z o   G ,   De   L o re n z o   A ,   M a u ri  M ,   M e d v e t  E,   S o rio   E. ,   " A u to m a ti c   g e n e ra ti o n   o f   re g u lar  e x p re ss io n s   f ro m   e x a m p les   w it h   g e n e ti c   p ro g ra m m in g ,"   In :  Pro c e e d in g s  o f  th e   fo u rte e n th   i n ter n a ti o n a l  c o n fer e n c e   o n   Ge n e ti c   a n d   e v o lu ti o n a ry   c o m p u t a ti o n   c o n fer e n c e   c o mp a n io n   -   GECCO  C o mp a n io n   ’ 1 2 ,   [ On l in e ] .   2 0 1 2 .   A v a il a b le  f ro m :   h tt p : // d x . d o i. o rg /1 0 . 1 1 4 5 / 2 3 3 0 7 8 4 . 2 3 3 1 0 0 0 .   [5 ]   " 7 . 2 .   re   —   Re g u lar  e x p re ss io n   o p e ra ti o n s  —   P y th o n   2 . 7 . 1 5   d o c u m e n tatio n "   [ On l i n e ] .   Av a il a b le  f ro m :  h tt p s:/ /d o c s.p y th o n . o rg /2 /l i b ra ry /r e . h tm l ,  [ c it e d   2 0 1 8   De c   2 6 ] .   [6 ]   Kis m a n ,   Kism a n ,   Isa   S M . ,   " Hib e rn a te  ORM  q u e ry   si m p li f ica ti o n   u si n g   h ib e r n a te  c rit e ria  e x ten sio n   (HCE) ,"   In :   2 0 1 6   3 rd   N a ti o n a l  Fo u n d a ti o n   f o r S c ien c e   a n d   T e c h n o lo g y   De v e lo p me n t  Co n fer e n c e   o n   In fo rm a t io n   a n d   Co m p u ter   S c ien c e   ( NICS ) ,   [ O n li n e ] ,   2 0 1 6 .   Av a il a b le f ro m :  h tt p :/ / d x . d o i . o rg / 1 0 . 1 1 0 9 / n ics . 2 0 1 6 . 7 7 2 5 6 5 6   [7 ]   " Qu e r y in g   Ob jec ts  w it h   Crit e ria ,"   In :  Pr o   Hib e rn a te  3 .  p p .   1 3 1 – 4 4 .   [8 ]   L in w o o d   J,  M i n ter D. ,   " A d v a n c e d   Qu e ries   Us in g   Crit e ria ,"   In :   Beg in n i n g   Hib e rn a te ,   2 0 1 0 ,   p p .   2 1 5 – 25.   Evaluation Warning : The document was created with Spire.PDF for Python.
I n t J   E lec  &   C o m p   E n g     I SS N:  2 0 8 8 - 8708       A   r eg ex crit eria   a p i to   co mp let e  th e  p o w er o f reg u la r   ex p r ess io n s   en g in e   ( B o u lch a h o u b   Ha s s a n )   3193   [9 ]   " P a tt e rn   (Ja v a   P latf o rm   S E  7   ) ,”   [ On li n e ] ,   2 0 1 8 ,   A v a il a b le  f ro m :  h tt p s:// d o c s. o ra c le.co m /j a v a se /7 /d o c s/a p i/ jav a   /u ti l/ re g e x /P a tt e rn . h tm l ,  [ c it e d   2 0 1 8   De c   2 6 ] .   [1 0 ]   S p ish a k   E,   Die tl   W ,   Ern st  M D. ,   " A   t y p e   s y ste m   f o r  re g u lar  e x p re ss io n s ,"   In :  Pro c e e d in g s  o f  th e   1 4 th   W o rk sh o p   o n   Fo rm a l  T e c h n iq u e s  fo r  J a v a - li k e   Pro g ra ms   -   FT fJP  ’1 2   [ O n li n e ] ,   2 0 1 2 ,   A v a il a b le  f ro m :  h tt p : // d x . d o i. o rg   /1 0 . 1 1 4 5 /2 3 1 8 2 0 2 . 2 3 1 8 2 0 7   [1 1 ]   M c Cu ll o c h   W S . ,   P it ts  W . ,   " A   l o g ica l  c a lcu lu s  o f   th e   id e a s  i m m a n e n t  in   n e rv o u s  a c ti v it y ,"   Bu ll   M a th   Bi o p h y s ,     v o l.   5 ,   n o .   4 ,   p p .   1 1 5 – 33 ,  1 9 4 3 .   [1 2 ]   Kle e n e   S C. ,   " Re p re se n tatio n   o f   E v e n ts i n   Ne rv e   Ne ts an d   F i n it e   A u to m a ta.  In :  Au to ma ta   S t u d ies   ( AM - 34) ,   1 9 5 1 .   [1 3 ]   T h o m p so n   K. ,   " P ro g ra m m in g   T e c h n iq u e s:  Re g u lar  e x p re ss io n   se a rc h   a lg o rit h m ,"   Co mm u n   ACM ,   v o l.   11 ,   n o .   6 ,    p p .   4 1 9 – 22 ,  1 9 6 8 .   [1 4 ]   Re g u lar e x p re ss io n s ,   [ On l in e ] ,   Av a il a b le  f ro m :  h tt p :/ /www . f o n . h u m . u v a . n l/ p ra a t/ m a n u a l/ Re g u lar_ e x p re ss io n s.h tm l ,  [ c it e d   2 0 1 8   A u g   1 5 ] .   [1 5 ]   HD F S   A rc h it e c tu re   G u id e ,   [ O n li n e ] ,   A v a il a b le  f ro m :  h tt p s:// h a d o o p . a p a c h e . o rg /d o c s/r1 . 2 . 1 /h d f s_ d e sig n . h tm l ,  [ c it e d   2 0 1 8   A u g   1 8 ] .   [1 6 ]   M a p Re d u c e   T u to rial ,   [ O n li n e ] ,   Av a il a b le  f ro m :  h tt p s:// h a d o o p . a p a c h e . o rg /d o c s/r1 . 2 . 1 /m a p re d _ t u t o rial. h tm l ,  [ c it e d   2 0 1 8   J u l  3 1 ] .   [1 7 ]   jav a . u ti l. re g e x   (J a v a   P latf o rm   S E  7   ) ,   [ On li n e ] ,   2 0 1 8 ,   A v a il a b le  f ro m :   h tt p s:// d o c s.o ra c le.co m /j a v a s e /7 /d o c s/a p i   /j a v a /u ti l/ re g e x /p a c k a g e - su m m a r y . h t m l ,  [ c it e d   2 0 1 8   A u g   1 3 ] .   [1 8 ]   o rg . h ib e r n a te  (Hib e rn a te  A P I  Do c u m e n tatio n ) ,   [ O n li n e ] .   Av a il a b le  f ro m :  h tt p s:// d o c s.jb o ss . o rg /h i b e rn a t e   /co re /3 . 2 /ap i/ o rg /h i b e rn a te/p a c k a g e - su m m a r y . h tm l ,  [ c it e d   2 0 1 8   A u g   1 3 ] .   [1 9 ]   In   se a rc h   o f   th e   p e r f e c t  UR L   v a li d a ti o n   re g e x ,   [ On li n e ] ,   A v a il a b le   f ro m :  h tt p s:// m a th ias b y n e n s.b e /d e m o /u rl - re g e x ,  [ c it e d   2 0 1 8   De c   2 6 ].       Evaluation Warning : The document was created with Spire.PDF for Python.