Guest User

Untitled

a guest
Jan 17th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.49 KB | None | 0 0
  1. /
  2. ^ # start of string
  3. ( # first group start
  4. (?:
  5. (?:[^?+*{}()[]\|]+ # literals and ^, $
  6. | \. # escaped characters
  7. | [ (?: ^?\. | ^[^\] | [^\^] ) # character classes
  8. (?: [^]\]+ | \. )* ]
  9. | ( (?:?[:=!]|?<[=!]|?>)? (?1)?? ) # parenthesis, with recursive content
  10. | (? (?:R|[+-]?d+) ) # recursive matching
  11. )
  12. (?: (?:[?+*]|{d+(?:,d*)?}) [?+]? )? # quantifiers
  13. | | # alternative
  14. )* # repeat content
  15. ) # end first group
  16. $ # end of string
  17. /
  18.  
  19. /^((?:(?:[^?+*{}()[]\|]+|\.|[(?:^?\.|^[^\]|[^\^])(?:[^]\]+|\.)*]|((?:?[:=!]|?<[=!]|?>)?(?1)??)|(?(?:R|[+-]?d+)))(?:(?:[?+*]|{d+(?:,d*)?})[?+]?)?||)*)$/
  20.  
  21. ^ # start of string
  22. (?:
  23. (?: [^?+*{}()[]\|]+ # literals and ^, $
  24. | \. # escaped characters
  25. | [ (?: ^?\. | ^[^\] | [^\^] ) # character classes
  26. (?: [^]\]+ | \. )* ]
  27. | ( (?:?[:=!]
  28. | ?<[=!]
  29. | ?>
  30. | ?<[^Wd]w*>
  31. | ?'[^Wd]w*'
  32. )? # opening of group
  33. (?<N>) # increment counter
  34. | ) # closing of group
  35. (?<-N>) # decrement counter
  36. )
  37. (?: (?:[?+*]|{d+(?:,d*)?}) [?+]? )? # quantifiers
  38. | | # alternative
  39. )* # repeat content
  40. $ # end of string
  41. (?(N)(?!)) # fail if counter is non-zero.
  42.  
  43. ^(?:(?:[^?+*{}()[]\|]+|\.|[(?:^?\.|^[^\]|[^\^])(?:[^]\]+|\.)*]|((?:?[:=!]|?<[=!]|?>|?<[^Wd]w*>|?'[^Wd]w*')?(?<N>)|)(?<-N>))(?:(?:[?+*]|{d+(?:,d*)?})[?+]?)?||)*$(?(N)(?!))
  44.  
  45. SKIP :
  46. {
  47. " "
  48. | "r"
  49. | "t"
  50. | "n"
  51. }
  52. TOKEN :
  53. {
  54. < DIGITO: ["0" - "9"] >
  55. | < MAYUSCULA: ["A" - "Z"] >
  56. | < MINUSCULA: ["a" - "z"] >
  57. | < LAMBDA: "LAMBDA" >
  58. | < VACIO: "VACIO" >
  59. }
  60.  
  61. IRegularExpression Expression() :
  62. {
  63. IRegularExpression r;
  64. }
  65. {
  66. r=Alternation() { return r; }
  67. }
  68.  
  69. // Matchea disyunciones: ER | ER
  70. IRegularExpression Alternation() :
  71. {
  72. IRegularExpression r1 = null, r2 = null;
  73. }
  74. {
  75. r1=Concatenation() ( "|" r2=Alternation() )?
  76. {
  77. if (r2 == null) {
  78. return r1;
  79. } else {
  80. return createAlternation(r1,r2);
  81. }
  82. }
  83. }
  84.  
  85. // Matchea concatenaciones: ER.ER
  86. IRegularExpression Concatenation() :
  87. {
  88. IRegularExpression r1 = null, r2 = null;
  89. }
  90. {
  91. r1=Repetition() ( "." r2=Repetition() { r1 = createConcatenation(r1,r2); } )*
  92. { return r1; }
  93. }
  94.  
  95. // Matchea repeticiones: ER*
  96. IRegularExpression Repetition() :
  97. {
  98. IRegularExpression r;
  99. }
  100. {
  101. r=Atom() ( "*" { r = createRepetition(r); } )*
  102. { return r; }
  103. }
  104.  
  105. // Matchea regex atomicas: (ER), Terminal, Vacio, Lambda
  106. IRegularExpression Atom() :
  107. {
  108. String t;
  109. IRegularExpression r;
  110. }
  111. {
  112. ( "(" r=Expression() ")" {return r;})
  113. | t=Terminal() { return createTerminal(t); }
  114. | <LAMBDA> { return createLambda(); }
  115. | <VACIO> { return createEmpty(); }
  116. }
  117.  
  118. // Matchea un terminal (digito o minuscula) y devuelve su valor
  119. String Terminal() :
  120. {
  121. Token t;
  122. }
  123. {
  124. ( t=<DIGITO> | t=<MINUSCULA> ) { return t.image; }
  125. }
  126.  
  127. @preg_match($regexToTest, '');
Add Comment
Please, Sign In to add comment