rbs 4.1.0.pre.2-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (574) hide show
  1. checksums.yaml +7 -0
  2. data/.clang-format +75 -0
  3. data/.clangd +2 -0
  4. data/.github/dependabot.yml +24 -0
  5. data/.github/workflows/bundle-update.yml +63 -0
  6. data/.github/workflows/c-check.yml +61 -0
  7. data/.github/workflows/comments.yml +37 -0
  8. data/.github/workflows/dependabot.yml +30 -0
  9. data/.github/workflows/jruby.yml +67 -0
  10. data/.github/workflows/milestone.yml +83 -0
  11. data/.github/workflows/ruby.yml +158 -0
  12. data/.github/workflows/rust.yml +184 -0
  13. data/.github/workflows/truffleruby.yml +54 -0
  14. data/.github/workflows/typecheck.yml +39 -0
  15. data/.github/workflows/wasm.yml +53 -0
  16. data/.github/workflows/windows.yml +49 -0
  17. data/.gitignore +38 -0
  18. data/.rubocop.yml +72 -0
  19. data/BSDL +22 -0
  20. data/CHANGELOG.md +2292 -0
  21. data/COPYING +56 -0
  22. data/README.md +240 -0
  23. data/Rakefile +869 -0
  24. data/Steepfile +53 -0
  25. data/config.yml +913 -0
  26. data/core/array.rbs +4142 -0
  27. data/core/basic_object.rbs +376 -0
  28. data/core/binding.rbs +148 -0
  29. data/core/builtin.rbs +278 -0
  30. data/core/class.rbs +223 -0
  31. data/core/comparable.rbs +192 -0
  32. data/core/complex.rbs +812 -0
  33. data/core/constants.rbs +96 -0
  34. data/core/data.rbs +415 -0
  35. data/core/dir.rbs +993 -0
  36. data/core/encoding.rbs +1368 -0
  37. data/core/enumerable.rbs +2506 -0
  38. data/core/enumerator/arithmetic_sequence.rbs +70 -0
  39. data/core/enumerator/product.rbs +92 -0
  40. data/core/enumerator.rbs +705 -0
  41. data/core/env.rbs +6 -0
  42. data/core/errno.rbs +682 -0
  43. data/core/errors.rbs +789 -0
  44. data/core/exception.rbs +485 -0
  45. data/core/false_class.rbs +82 -0
  46. data/core/fiber.rbs +570 -0
  47. data/core/fiber_error.rbs +11 -0
  48. data/core/file.rbs +2045 -0
  49. data/core/file_constants.rbs +463 -0
  50. data/core/file_stat.rbs +534 -0
  51. data/core/file_test.rbs +331 -0
  52. data/core/float.rbs +1316 -0
  53. data/core/gc.rbs +788 -0
  54. data/core/global_variables.rbs +184 -0
  55. data/core/hash.rbs +2183 -0
  56. data/core/integer.rbs +1374 -0
  57. data/core/io/buffer.rbs +995 -0
  58. data/core/io/wait.rbs +48 -0
  59. data/core/io.rbs +3472 -0
  60. data/core/kernel.rbs +3172 -0
  61. data/core/marshal.rbs +207 -0
  62. data/core/match_data.rbs +637 -0
  63. data/core/math.rbs +770 -0
  64. data/core/method.rbs +422 -0
  65. data/core/module.rbs +1856 -0
  66. data/core/nil_class.rbs +210 -0
  67. data/core/numeric.rbs +832 -0
  68. data/core/object.rbs +108 -0
  69. data/core/object_space/weak_key_map.rbs +166 -0
  70. data/core/object_space.rbs +197 -0
  71. data/core/pathname.rbs +1322 -0
  72. data/core/proc.rbs +905 -0
  73. data/core/process.rbs +2316 -0
  74. data/core/ractor.rbs +924 -0
  75. data/core/random.rbs +255 -0
  76. data/core/range.rbs +1209 -0
  77. data/core/rational.rbs +502 -0
  78. data/core/rb_config.rbs +88 -0
  79. data/core/rbs/ops.rbs +154 -0
  80. data/core/rbs/unnamed/argf.rbs +1236 -0
  81. data/core/rbs/unnamed/env_class.rbs +1214 -0
  82. data/core/rbs/unnamed/main_class.rbs +123 -0
  83. data/core/rbs/unnamed/random.rbs +186 -0
  84. data/core/refinement.rbs +59 -0
  85. data/core/regexp.rbs +1974 -0
  86. data/core/ruby.rbs +53 -0
  87. data/core/ruby_vm.rbs +809 -0
  88. data/core/rubygems/basic_specification.rbs +6 -0
  89. data/core/rubygems/config_file.rbs +38 -0
  90. data/core/rubygems/dependency_installer.rbs +6 -0
  91. data/core/rubygems/errors.rbs +109 -0
  92. data/core/rubygems/installer.rbs +15 -0
  93. data/core/rubygems/path_support.rbs +6 -0
  94. data/core/rubygems/platform.rbs +7 -0
  95. data/core/rubygems/request_set.rbs +49 -0
  96. data/core/rubygems/requirement.rbs +148 -0
  97. data/core/rubygems/rubygems.rbs +1105 -0
  98. data/core/rubygems/source_list.rbs +15 -0
  99. data/core/rubygems/specification.rbs +23 -0
  100. data/core/rubygems/stream_ui.rbs +5 -0
  101. data/core/rubygems/uninstaller.rbs +10 -0
  102. data/core/rubygems/version.rbs +293 -0
  103. data/core/set.rbs +751 -0
  104. data/core/signal.rbs +110 -0
  105. data/core/string.rbs +5532 -0
  106. data/core/struct.rbs +668 -0
  107. data/core/symbol.rbs +482 -0
  108. data/core/thread.rbs +1826 -0
  109. data/core/thread_group.rbs +79 -0
  110. data/core/time.rbs +1793 -0
  111. data/core/trace_point.rbs +483 -0
  112. data/core/true_class.rbs +98 -0
  113. data/core/unbound_method.rbs +337 -0
  114. data/core/warning.rbs +87 -0
  115. data/docs/CONTRIBUTING.md +107 -0
  116. data/docs/aliases.md +79 -0
  117. data/docs/architecture.md +110 -0
  118. data/docs/collection.md +192 -0
  119. data/docs/config.md +171 -0
  120. data/docs/data_and_struct.md +86 -0
  121. data/docs/encoding.md +56 -0
  122. data/docs/gem.md +56 -0
  123. data/docs/inline.md +634 -0
  124. data/docs/rbs_by_example.md +309 -0
  125. data/docs/repo.md +125 -0
  126. data/docs/rust.md +96 -0
  127. data/docs/sigs.md +167 -0
  128. data/docs/stdlib.md +147 -0
  129. data/docs/syntax.md +940 -0
  130. data/docs/tools.md +17 -0
  131. data/docs/type_fingerprint.md +21 -0
  132. data/docs/wasm_serialization.md +80 -0
  133. data/exe/rbs +7 -0
  134. data/ext/rbs_extension/ast_translation.c +1855 -0
  135. data/ext/rbs_extension/ast_translation.h +41 -0
  136. data/ext/rbs_extension/class_constants.c +187 -0
  137. data/ext/rbs_extension/class_constants.h +104 -0
  138. data/ext/rbs_extension/compat.h +10 -0
  139. data/ext/rbs_extension/extconf.rb +40 -0
  140. data/ext/rbs_extension/legacy_location.c +294 -0
  141. data/ext/rbs_extension/legacy_location.h +82 -0
  142. data/ext/rbs_extension/main.c +613 -0
  143. data/ext/rbs_extension/rbs_extension.h +16 -0
  144. data/ext/rbs_extension/rbs_string_bridging.c +9 -0
  145. data/ext/rbs_extension/rbs_string_bridging.h +24 -0
  146. data/goodcheck.yml +91 -0
  147. data/include/rbs/ast.h +1047 -0
  148. data/include/rbs/defines.h +99 -0
  149. data/include/rbs/lexer.h +207 -0
  150. data/include/rbs/location.h +40 -0
  151. data/include/rbs/parser.h +153 -0
  152. data/include/rbs/serialize.h +39 -0
  153. data/include/rbs/string.h +47 -0
  154. data/include/rbs/util/rbs_allocator.h +59 -0
  155. data/include/rbs/util/rbs_assert.h +20 -0
  156. data/include/rbs/util/rbs_buffer.h +83 -0
  157. data/include/rbs/util/rbs_constant_pool.h +155 -0
  158. data/include/rbs/util/rbs_encoding.h +282 -0
  159. data/include/rbs/util/rbs_unescape.h +24 -0
  160. data/include/rbs.h +14 -0
  161. data/lib/rbs/ancestor_graph.rb +92 -0
  162. data/lib/rbs/annotate/annotations.rb +199 -0
  163. data/lib/rbs/annotate/formatter.rb +82 -0
  164. data/lib/rbs/annotate/rdoc_annotator.rb +398 -0
  165. data/lib/rbs/annotate/rdoc_source.rb +131 -0
  166. data/lib/rbs/annotate.rb +8 -0
  167. data/lib/rbs/ast/annotation.rb +29 -0
  168. data/lib/rbs/ast/comment.rb +29 -0
  169. data/lib/rbs/ast/declarations.rb +472 -0
  170. data/lib/rbs/ast/directives.rb +49 -0
  171. data/lib/rbs/ast/members.rb +451 -0
  172. data/lib/rbs/ast/ruby/annotations.rb +451 -0
  173. data/lib/rbs/ast/ruby/comment_block.rb +247 -0
  174. data/lib/rbs/ast/ruby/declarations.rb +291 -0
  175. data/lib/rbs/ast/ruby/helpers/constant_helper.rb +28 -0
  176. data/lib/rbs/ast/ruby/helpers/location_helper.rb +15 -0
  177. data/lib/rbs/ast/ruby/members.rb +762 -0
  178. data/lib/rbs/ast/type_param.rb +235 -0
  179. data/lib/rbs/ast/visitor.rb +137 -0
  180. data/lib/rbs/buffer.rb +189 -0
  181. data/lib/rbs/builtin_names.rb +58 -0
  182. data/lib/rbs/cli/colored_io.rb +48 -0
  183. data/lib/rbs/cli/diff.rb +84 -0
  184. data/lib/rbs/cli/validate.rb +294 -0
  185. data/lib/rbs/cli.rb +1253 -0
  186. data/lib/rbs/collection/cleaner.rb +38 -0
  187. data/lib/rbs/collection/config/lockfile.rb +92 -0
  188. data/lib/rbs/collection/config/lockfile_generator.rb +269 -0
  189. data/lib/rbs/collection/config.rb +81 -0
  190. data/lib/rbs/collection/installer.rb +32 -0
  191. data/lib/rbs/collection/sources/base.rb +14 -0
  192. data/lib/rbs/collection/sources/git.rb +265 -0
  193. data/lib/rbs/collection/sources/local.rb +81 -0
  194. data/lib/rbs/collection/sources/rubygems.rb +48 -0
  195. data/lib/rbs/collection/sources/stdlib.rb +50 -0
  196. data/lib/rbs/collection/sources.rb +38 -0
  197. data/lib/rbs/collection.rb +16 -0
  198. data/lib/rbs/constant.rb +28 -0
  199. data/lib/rbs/definition.rb +415 -0
  200. data/lib/rbs/definition_builder/ancestor_builder.rb +678 -0
  201. data/lib/rbs/definition_builder/method_builder.rb +295 -0
  202. data/lib/rbs/definition_builder.rb +1054 -0
  203. data/lib/rbs/diff.rb +131 -0
  204. data/lib/rbs/environment/class_entry.rb +69 -0
  205. data/lib/rbs/environment/module_entry.rb +66 -0
  206. data/lib/rbs/environment/use_map.rb +77 -0
  207. data/lib/rbs/environment.rb +1028 -0
  208. data/lib/rbs/environment_loader.rb +167 -0
  209. data/lib/rbs/environment_walker.rb +155 -0
  210. data/lib/rbs/errors.rb +634 -0
  211. data/lib/rbs/factory.rb +18 -0
  212. data/lib/rbs/file_finder.rb +28 -0
  213. data/lib/rbs/inline_parser/comment_association.rb +117 -0
  214. data/lib/rbs/inline_parser.rb +568 -0
  215. data/lib/rbs/location_aux.rb +170 -0
  216. data/lib/rbs/locator.rb +247 -0
  217. data/lib/rbs/method_type.rb +145 -0
  218. data/lib/rbs/namespace.rb +154 -0
  219. data/lib/rbs/parser/lex_result.rb +15 -0
  220. data/lib/rbs/parser/token.rb +23 -0
  221. data/lib/rbs/parser_aux.rb +142 -0
  222. data/lib/rbs/prototype/helpers.rb +197 -0
  223. data/lib/rbs/prototype/node_usage.rb +99 -0
  224. data/lib/rbs/prototype/rb.rb +816 -0
  225. data/lib/rbs/prototype/rbi.rb +625 -0
  226. data/lib/rbs/prototype/runtime/helpers.rb +59 -0
  227. data/lib/rbs/prototype/runtime/reflection.rb +19 -0
  228. data/lib/rbs/prototype/runtime/value_object_generator.rb +279 -0
  229. data/lib/rbs/prototype/runtime.rb +680 -0
  230. data/lib/rbs/repository.rb +127 -0
  231. data/lib/rbs/resolver/constant_resolver.rb +219 -0
  232. data/lib/rbs/resolver/type_name_resolver.rb +167 -0
  233. data/lib/rbs/rewriter.rb +70 -0
  234. data/lib/rbs/sorter.rb +198 -0
  235. data/lib/rbs/source.rb +99 -0
  236. data/lib/rbs/substitution.rb +83 -0
  237. data/lib/rbs/subtractor.rb +204 -0
  238. data/lib/rbs/test/errors.rb +80 -0
  239. data/lib/rbs/test/guaranteed.rb +30 -0
  240. data/lib/rbs/test/hook.rb +212 -0
  241. data/lib/rbs/test/observer.rb +19 -0
  242. data/lib/rbs/test/setup.rb +84 -0
  243. data/lib/rbs/test/setup_helper.rb +50 -0
  244. data/lib/rbs/test/tester.rb +167 -0
  245. data/lib/rbs/test/type_check.rb +457 -0
  246. data/lib/rbs/test.rb +112 -0
  247. data/lib/rbs/type_alias_dependency.rb +100 -0
  248. data/lib/rbs/type_alias_regularity.rb +126 -0
  249. data/lib/rbs/type_name.rb +122 -0
  250. data/lib/rbs/types.rb +1604 -0
  251. data/lib/rbs/unit_test/convertibles.rb +177 -0
  252. data/lib/rbs/unit_test/spy.rb +138 -0
  253. data/lib/rbs/unit_test/type_assertions.rb +383 -0
  254. data/lib/rbs/unit_test/with_aliases.rb +145 -0
  255. data/lib/rbs/unit_test.rb +6 -0
  256. data/lib/rbs/validator.rb +186 -0
  257. data/lib/rbs/variance_calculator.rb +189 -0
  258. data/lib/rbs/vendorer.rb +71 -0
  259. data/lib/rbs/version.rb +5 -0
  260. data/lib/rbs/wasm/deserializer.rb +213 -0
  261. data/lib/rbs/wasm/jars/asm-analysis.jar +0 -0
  262. data/lib/rbs/wasm/jars/asm-commons.jar +0 -0
  263. data/lib/rbs/wasm/jars/asm-tree.jar +0 -0
  264. data/lib/rbs/wasm/jars/asm-util.jar +0 -0
  265. data/lib/rbs/wasm/jars/asm.jar +0 -0
  266. data/lib/rbs/wasm/jars/compiler.jar +0 -0
  267. data/lib/rbs/wasm/jars/log.jar +0 -0
  268. data/lib/rbs/wasm/jars/runtime.jar +0 -0
  269. data/lib/rbs/wasm/jars/wasi.jar +0 -0
  270. data/lib/rbs/wasm/jars/wasm.jar +0 -0
  271. data/lib/rbs/wasm/location.rb +61 -0
  272. data/lib/rbs/wasm/parser.rb +137 -0
  273. data/lib/rbs/wasm/rbs_parser.wasm +0 -0
  274. data/lib/rbs/wasm/runtime.rb +217 -0
  275. data/lib/rbs/wasm/serialization_schema.rb +110 -0
  276. data/lib/rbs/writer.rb +424 -0
  277. data/lib/rbs.rb +117 -0
  278. data/lib/rdoc/discover.rb +20 -0
  279. data/lib/rdoc_plugin/parser.rb +163 -0
  280. data/rbs.gemspec +68 -0
  281. data/schema/annotation.json +14 -0
  282. data/schema/comment.json +26 -0
  283. data/schema/decls.json +326 -0
  284. data/schema/function.json +87 -0
  285. data/schema/location.json +56 -0
  286. data/schema/members.json +266 -0
  287. data/schema/methodType.json +50 -0
  288. data/schema/typeParam.json +52 -0
  289. data/schema/types.json +317 -0
  290. data/sig/ancestor_builder.rbs +163 -0
  291. data/sig/ancestor_graph.rbs +60 -0
  292. data/sig/annotate/annotations.rbs +102 -0
  293. data/sig/annotate/formatter.rbs +24 -0
  294. data/sig/annotate/rdoc_annotater.rbs +85 -0
  295. data/sig/annotate/rdoc_source.rbs +32 -0
  296. data/sig/annotation.rbs +27 -0
  297. data/sig/ast/ruby/annotations.rbs +470 -0
  298. data/sig/ast/ruby/comment_block.rbs +127 -0
  299. data/sig/ast/ruby/declarations.rbs +158 -0
  300. data/sig/ast/ruby/helpers/constant_helper.rbs +11 -0
  301. data/sig/ast/ruby/helpers/location_helper.rbs +15 -0
  302. data/sig/ast/ruby/members.rbs +198 -0
  303. data/sig/buffer.rbs +108 -0
  304. data/sig/builtin_names.rbs +44 -0
  305. data/sig/cli/colored_io.rbs +15 -0
  306. data/sig/cli/diff.rbs +15 -0
  307. data/sig/cli/validate.rbs +47 -0
  308. data/sig/cli.rbs +89 -0
  309. data/sig/collection/cleaner.rbs +13 -0
  310. data/sig/collection/config/lockfile.rbs +74 -0
  311. data/sig/collection/config/lockfile_generator.rbs +68 -0
  312. data/sig/collection/config.rbs +46 -0
  313. data/sig/collection/installer.rbs +17 -0
  314. data/sig/collection/sources.rbs +214 -0
  315. data/sig/collection.rbs +4 -0
  316. data/sig/comment.rbs +26 -0
  317. data/sig/constant.rbs +21 -0
  318. data/sig/declarations.rbs +274 -0
  319. data/sig/definition.rbs +232 -0
  320. data/sig/definition_builder.rbs +181 -0
  321. data/sig/diff.rbs +28 -0
  322. data/sig/directives.rbs +77 -0
  323. data/sig/environment/class_entry.rbs +50 -0
  324. data/sig/environment/module_entry.rbs +50 -0
  325. data/sig/environment.rbs +286 -0
  326. data/sig/environment_loader.rbs +111 -0
  327. data/sig/environment_walker.rbs +65 -0
  328. data/sig/errors.rbs +408 -0
  329. data/sig/factory.rbs +5 -0
  330. data/sig/file_finder.rbs +28 -0
  331. data/sig/inline_parser/comment_association.rbs +71 -0
  332. data/sig/inline_parser.rbs +126 -0
  333. data/sig/location.rbs +135 -0
  334. data/sig/locator.rbs +56 -0
  335. data/sig/manifest.yaml +5 -0
  336. data/sig/members.rbs +258 -0
  337. data/sig/method_builder.rbs +89 -0
  338. data/sig/method_types.rbs +58 -0
  339. data/sig/namespace.rbs +161 -0
  340. data/sig/parser.rbs +164 -0
  341. data/sig/prototype/helpers.rbs +29 -0
  342. data/sig/prototype/node_usage.rbs +20 -0
  343. data/sig/prototype/rb.rbs +96 -0
  344. data/sig/prototype/rbi.rbs +75 -0
  345. data/sig/prototype/runtime.rbs +182 -0
  346. data/sig/rbs.rbs +21 -0
  347. data/sig/rdoc/rbs.rbs +67 -0
  348. data/sig/repository.rbs +85 -0
  349. data/sig/resolver/constant_resolver.rbs +92 -0
  350. data/sig/resolver/context.rbs +34 -0
  351. data/sig/resolver/type_name_resolver.rbs +61 -0
  352. data/sig/rewriter.rbs +45 -0
  353. data/sig/shims/bundler.rbs +38 -0
  354. data/sig/shims/enumerable.rbs +5 -0
  355. data/sig/shims/rubygems.rbs +19 -0
  356. data/sig/sorter.rbs +41 -0
  357. data/sig/source.rbs +48 -0
  358. data/sig/substitution.rbs +48 -0
  359. data/sig/subtractor.rbs +37 -0
  360. data/sig/test/errors.rbs +52 -0
  361. data/sig/test/guranteed.rbs +9 -0
  362. data/sig/test/type_check.rbs +19 -0
  363. data/sig/test.rbs +82 -0
  364. data/sig/type_alias_dependency.rbs +53 -0
  365. data/sig/type_alias_regularity.rbs +98 -0
  366. data/sig/type_param.rbs +115 -0
  367. data/sig/typename.rbs +89 -0
  368. data/sig/types.rbs +578 -0
  369. data/sig/unit_test/convertibles.rbs +154 -0
  370. data/sig/unit_test/spy.rbs +22 -0
  371. data/sig/unit_test/type_assertions.rbs +211 -0
  372. data/sig/unit_test/with_aliases.rbs +136 -0
  373. data/sig/use_map.rbs +35 -0
  374. data/sig/util.rbs +9 -0
  375. data/sig/validator.rbs +63 -0
  376. data/sig/variance_calculator.rbs +87 -0
  377. data/sig/vendorer.rbs +51 -0
  378. data/sig/version.rbs +3 -0
  379. data/sig/visitor.rbs +47 -0
  380. data/sig/wasm/deserializer.rbs +66 -0
  381. data/sig/wasm/serialization_schema.rbs +13 -0
  382. data/sig/writer.rbs +127 -0
  383. data/src/ast.c +1628 -0
  384. data/src/lexer.c +3217 -0
  385. data/src/lexer.re +155 -0
  386. data/src/lexstate.c +217 -0
  387. data/src/location.c +31 -0
  388. data/src/parser.c +4255 -0
  389. data/src/serialize.c +958 -0
  390. data/src/string.c +41 -0
  391. data/src/util/rbs_allocator.c +162 -0
  392. data/src/util/rbs_assert.c +19 -0
  393. data/src/util/rbs_buffer.c +54 -0
  394. data/src/util/rbs_constant_pool.c +268 -0
  395. data/src/util/rbs_encoding.c +21308 -0
  396. data/src/util/rbs_unescape.c +167 -0
  397. data/stdlib/abbrev/0/abbrev.rbs +66 -0
  398. data/stdlib/abbrev/0/array.rbs +26 -0
  399. data/stdlib/base64/0/base64.rbs +355 -0
  400. data/stdlib/benchmark/0/benchmark.rbs +452 -0
  401. data/stdlib/bigdecimal/0/big_decimal.rbs +1647 -0
  402. data/stdlib/bigdecimal-math/0/big_math.rbs +280 -0
  403. data/stdlib/bigdecimal-math/0/manifest.yaml +2 -0
  404. data/stdlib/cgi/0/core.rbs +911 -0
  405. data/stdlib/cgi/0/manifest.yaml +4 -0
  406. data/stdlib/cgi-escape/0/escape.rbs +171 -0
  407. data/stdlib/coverage/0/coverage.rbs +266 -0
  408. data/stdlib/csv/0/csv.rbs +3776 -0
  409. data/stdlib/csv/0/manifest.yaml +3 -0
  410. data/stdlib/date/0/date.rbs +1598 -0
  411. data/stdlib/date/0/date_time.rbs +617 -0
  412. data/stdlib/date/0/time.rbs +26 -0
  413. data/stdlib/dbm/0/dbm.rbs +421 -0
  414. data/stdlib/delegate/0/delegator.rbs +187 -0
  415. data/stdlib/delegate/0/kernel.rbs +47 -0
  416. data/stdlib/delegate/0/simple_delegator.rbs +96 -0
  417. data/stdlib/did_you_mean/0/did_you_mean.rbs +344 -0
  418. data/stdlib/digest/0/digest.rbs +687 -0
  419. data/stdlib/erb/0/erb.rbs +933 -0
  420. data/stdlib/etc/0/etc.rbs +884 -0
  421. data/stdlib/fileutils/0/fileutils.rbs +1753 -0
  422. data/stdlib/find/0/find.rbs +49 -0
  423. data/stdlib/forwardable/0/forwardable.rbs +271 -0
  424. data/stdlib/io-console/0/io-console.rbs +414 -0
  425. data/stdlib/ipaddr/0/ipaddr.rbs +436 -0
  426. data/stdlib/json/0/json.rbs +1963 -0
  427. data/stdlib/kconv/0/kconv.rbs +166 -0
  428. data/stdlib/logger/0/formatter.rbs +45 -0
  429. data/stdlib/logger/0/log_device.rbs +100 -0
  430. data/stdlib/logger/0/logger.rbs +796 -0
  431. data/stdlib/logger/0/manifest.yaml +2 -0
  432. data/stdlib/logger/0/period.rbs +17 -0
  433. data/stdlib/logger/0/severity.rbs +34 -0
  434. data/stdlib/minitest/0/kernel.rbs +42 -0
  435. data/stdlib/minitest/0/minitest/abstract_reporter.rbs +52 -0
  436. data/stdlib/minitest/0/minitest/assertion.rbs +17 -0
  437. data/stdlib/minitest/0/minitest/assertions.rbs +590 -0
  438. data/stdlib/minitest/0/minitest/backtrace_filter.rbs +23 -0
  439. data/stdlib/minitest/0/minitest/bench_spec.rbs +102 -0
  440. data/stdlib/minitest/0/minitest/benchmark.rbs +259 -0
  441. data/stdlib/minitest/0/minitest/composite_reporter.rbs +25 -0
  442. data/stdlib/minitest/0/minitest/compress.rbs +13 -0
  443. data/stdlib/minitest/0/minitest/error_on_warning.rbs +3 -0
  444. data/stdlib/minitest/0/minitest/expectation.rbs +2 -0
  445. data/stdlib/minitest/0/minitest/expectations.rbs +21 -0
  446. data/stdlib/minitest/0/minitest/guard.rbs +64 -0
  447. data/stdlib/minitest/0/minitest/mock.rbs +64 -0
  448. data/stdlib/minitest/0/minitest/parallel/executor.rbs +46 -0
  449. data/stdlib/minitest/0/minitest/parallel/test/class_methods.rbs +5 -0
  450. data/stdlib/minitest/0/minitest/parallel/test.rbs +3 -0
  451. data/stdlib/minitest/0/minitest/parallel.rbs +2 -0
  452. data/stdlib/minitest/0/minitest/pride_io.rbs +62 -0
  453. data/stdlib/minitest/0/minitest/pride_lol.rbs +19 -0
  454. data/stdlib/minitest/0/minitest/progress_reporter.rbs +11 -0
  455. data/stdlib/minitest/0/minitest/reportable.rbs +53 -0
  456. data/stdlib/minitest/0/minitest/reporter.rbs +5 -0
  457. data/stdlib/minitest/0/minitest/result.rbs +28 -0
  458. data/stdlib/minitest/0/minitest/runnable.rbs +163 -0
  459. data/stdlib/minitest/0/minitest/skip.rbs +6 -0
  460. data/stdlib/minitest/0/minitest/spec/dsl/instance_methods.rbs +48 -0
  461. data/stdlib/minitest/0/minitest/spec/dsl.rbs +129 -0
  462. data/stdlib/minitest/0/minitest/spec.rbs +11 -0
  463. data/stdlib/minitest/0/minitest/statistics_reporter.rbs +81 -0
  464. data/stdlib/minitest/0/minitest/summary_reporter.rbs +18 -0
  465. data/stdlib/minitest/0/minitest/test/lifecycle_hooks.rbs +92 -0
  466. data/stdlib/minitest/0/minitest/test.rbs +69 -0
  467. data/stdlib/minitest/0/minitest/unexpected_error.rbs +12 -0
  468. data/stdlib/minitest/0/minitest/unexpected_warning.rbs +6 -0
  469. data/stdlib/minitest/0/minitest/unit/test_case.rbs +3 -0
  470. data/stdlib/minitest/0/minitest/unit.rbs +4 -0
  471. data/stdlib/minitest/0/minitest.rbs +115 -0
  472. data/stdlib/monitor/0/monitor.rbs +363 -0
  473. data/stdlib/mutex_m/0/mutex_m.rbs +104 -0
  474. data/stdlib/net-http/0/manifest.yaml +3 -0
  475. data/stdlib/net-http/0/net-http.rbs +5580 -0
  476. data/stdlib/net-protocol/0/manifest.yaml +2 -0
  477. data/stdlib/net-protocol/0/net-protocol.rbs +56 -0
  478. data/stdlib/net-smtp/0/manifest.yaml +2 -0
  479. data/stdlib/net-smtp/0/net-smtp.rbs +55 -0
  480. data/stdlib/nkf/0/nkf.rbs +402 -0
  481. data/stdlib/objspace/0/objspace.rbs +470 -0
  482. data/stdlib/observable/0/observable.rbs +217 -0
  483. data/stdlib/open-uri/0/manifest.yaml +4 -0
  484. data/stdlib/open-uri/0/open-uri.rbs +433 -0
  485. data/stdlib/open3/0/open3.rbs +606 -0
  486. data/stdlib/openssl/0/manifest.yaml +3 -0
  487. data/stdlib/openssl/0/openssl.rbs +12231 -0
  488. data/stdlib/optparse/0/optparse.rbs +1734 -0
  489. data/stdlib/pathname/0/pathname.rbs +36 -0
  490. data/stdlib/pp/0/manifest.yaml +2 -0
  491. data/stdlib/pp/0/pp.rbs +301 -0
  492. data/stdlib/prettyprint/0/prettyprint.rbs +383 -0
  493. data/stdlib/pstore/0/pstore.rbs +608 -0
  494. data/stdlib/psych/0/core_ext.rbs +12 -0
  495. data/stdlib/psych/0/dbm.rbs +237 -0
  496. data/stdlib/psych/0/manifest.yaml +3 -0
  497. data/stdlib/psych/0/psych.rbs +455 -0
  498. data/stdlib/psych/0/store.rbs +57 -0
  499. data/stdlib/pty/0/pty.rbs +240 -0
  500. data/stdlib/random-formatter/0/random-formatter.rbs +277 -0
  501. data/stdlib/rdoc/0/code_object.rbs +52 -0
  502. data/stdlib/rdoc/0/comment.rbs +61 -0
  503. data/stdlib/rdoc/0/context.rbs +153 -0
  504. data/stdlib/rdoc/0/markup.rbs +117 -0
  505. data/stdlib/rdoc/0/options.rbs +76 -0
  506. data/stdlib/rdoc/0/parser.rbs +56 -0
  507. data/stdlib/rdoc/0/rdoc.rbs +393 -0
  508. data/stdlib/rdoc/0/ri.rbs +17 -0
  509. data/stdlib/rdoc/0/store.rbs +48 -0
  510. data/stdlib/rdoc/0/top_level.rbs +97 -0
  511. data/stdlib/resolv/0/manifest.yaml +3 -0
  512. data/stdlib/resolv/0/resolv.rbs +1787 -0
  513. data/stdlib/ripper/0/ripper.rbs +1654 -0
  514. data/stdlib/securerandom/0/manifest.yaml +2 -0
  515. data/stdlib/securerandom/0/securerandom.rbs +49 -0
  516. data/stdlib/shellwords/0/shellwords.rbs +229 -0
  517. data/stdlib/singleton/0/singleton.rbs +134 -0
  518. data/stdlib/socket/0/addrinfo.rbs +666 -0
  519. data/stdlib/socket/0/basic_socket.rbs +590 -0
  520. data/stdlib/socket/0/constants.rbs +2295 -0
  521. data/stdlib/socket/0/ip_socket.rbs +94 -0
  522. data/stdlib/socket/0/socket.rbs +4170 -0
  523. data/stdlib/socket/0/socket_error.rbs +5 -0
  524. data/stdlib/socket/0/tcp_server.rbs +192 -0
  525. data/stdlib/socket/0/tcp_socket.rbs +87 -0
  526. data/stdlib/socket/0/udp_socket.rbs +133 -0
  527. data/stdlib/socket/0/unix_server.rbs +169 -0
  528. data/stdlib/socket/0/unix_socket.rbs +172 -0
  529. data/stdlib/stringio/0/stringio.rbs +1681 -0
  530. data/stdlib/strscan/0/string_scanner.rbs +1648 -0
  531. data/stdlib/tempfile/0/tempfile.rbs +483 -0
  532. data/stdlib/time/0/time.rbs +434 -0
  533. data/stdlib/timeout/0/timeout.rbs +137 -0
  534. data/stdlib/tmpdir/0/tmpdir.rbs +69 -0
  535. data/stdlib/tsort/0/cyclic.rbs +8 -0
  536. data/stdlib/tsort/0/interfaces.rbs +20 -0
  537. data/stdlib/tsort/0/tsort.rbs +410 -0
  538. data/stdlib/uri/0/common.rbs +621 -0
  539. data/stdlib/uri/0/file.rbs +118 -0
  540. data/stdlib/uri/0/ftp.rbs +13 -0
  541. data/stdlib/uri/0/generic.rbs +1116 -0
  542. data/stdlib/uri/0/http.rbs +104 -0
  543. data/stdlib/uri/0/https.rbs +14 -0
  544. data/stdlib/uri/0/ldap.rbs +230 -0
  545. data/stdlib/uri/0/ldaps.rbs +14 -0
  546. data/stdlib/uri/0/mailto.rbs +92 -0
  547. data/stdlib/uri/0/rfc2396_parser.rbs +189 -0
  548. data/stdlib/uri/0/rfc3986_parser.rbs +2 -0
  549. data/stdlib/uri/0/ws.rbs +13 -0
  550. data/stdlib/uri/0/wss.rbs +9 -0
  551. data/stdlib/yaml/0/manifest.yaml +2 -0
  552. data/stdlib/yaml/0/yaml.rbs +1 -0
  553. data/stdlib/zlib/0/buf_error.rbs +10 -0
  554. data/stdlib/zlib/0/data_error.rbs +10 -0
  555. data/stdlib/zlib/0/deflate.rbs +211 -0
  556. data/stdlib/zlib/0/error.rbs +20 -0
  557. data/stdlib/zlib/0/gzip_file/crc_error.rbs +12 -0
  558. data/stdlib/zlib/0/gzip_file/error.rbs +23 -0
  559. data/stdlib/zlib/0/gzip_file/length_error.rbs +12 -0
  560. data/stdlib/zlib/0/gzip_file/no_footer.rbs +11 -0
  561. data/stdlib/zlib/0/gzip_file.rbs +156 -0
  562. data/stdlib/zlib/0/gzip_reader.rbs +293 -0
  563. data/stdlib/zlib/0/gzip_writer.rbs +168 -0
  564. data/stdlib/zlib/0/inflate.rbs +180 -0
  565. data/stdlib/zlib/0/mem_error.rbs +10 -0
  566. data/stdlib/zlib/0/need_dict.rbs +13 -0
  567. data/stdlib/zlib/0/stream_end.rbs +11 -0
  568. data/stdlib/zlib/0/stream_error.rbs +11 -0
  569. data/stdlib/zlib/0/version_error.rbs +11 -0
  570. data/stdlib/zlib/0/zlib.rbs +449 -0
  571. data/stdlib/zlib/0/zstream.rbs +201 -0
  572. data/wasm/README.md +59 -0
  573. data/wasm/rbs_wasm.c +411 -0
  574. metadata +660 -0
data/core/regexp.rbs ADDED
@@ -0,0 +1,1974 @@
1
+ # <!-- rdoc-file=re.c -->
2
+ # A [regular expression](https://en.wikipedia.org/wiki/Regular_expression) (also
3
+ # called a *regexp*) is a *match pattern* (also simply called a *pattern*).
4
+ #
5
+ # A common notation for a regexp uses enclosing slash characters:
6
+ #
7
+ # /foo/
8
+ #
9
+ # A regexp may be applied to a *target string*; The part of the string (if any)
10
+ # that matches the pattern is called a *match*, and may be said *to match*:
11
+ #
12
+ # re = /red/
13
+ # re.match?('redirect') # => true # Match at beginning of target.
14
+ # re.match?('bored') # => true # Match at end of target.
15
+ # re.match?('credit') # => true # Match within target.
16
+ # re.match?('foo') # => false # No match.
17
+ #
18
+ # ## Regexp Uses
19
+ #
20
+ # A regexp may be used:
21
+ #
22
+ # * To extract substrings based on a given pattern:
23
+ #
24
+ # re = /foo/ # => /foo/
25
+ # re.match('food') # => #<MatchData "foo">
26
+ # re.match('good') # => nil
27
+ #
28
+ # See sections [Method match](rdoc-ref:Regexp@Method+match) and [Operator
29
+ # =~](rdoc-ref:Regexp@Operator+-3D~).
30
+ #
31
+ # * To determine whether a string matches a given pattern:
32
+ #
33
+ # re.match?('food') # => true
34
+ # re.match?('good') # => false
35
+ #
36
+ # See section [Method match?](rdoc-ref:Regexp@Method+match-3F).
37
+ #
38
+ # * As an argument for calls to certain methods in other classes and modules;
39
+ # most such methods accept an argument that may be either a string or the
40
+ # (much more powerful) regexp.
41
+ #
42
+ # See [Regexp Methods](rdoc-ref:language/regexp/methods.rdoc).
43
+ #
44
+ # ## Regexp Objects
45
+ #
46
+ # A regexp object has:
47
+ #
48
+ # * A source; see [Sources](rdoc-ref:Regexp@Sources).
49
+ #
50
+ # * Several modes; see [Modes](rdoc-ref:Regexp@Modes).
51
+ #
52
+ # * A timeout; see [Timeouts](rdoc-ref:Regexp@Timeouts).
53
+ #
54
+ # * An encoding; see [Encodings](rdoc-ref:Regexp@Encodings).
55
+ #
56
+ # ## Creating a Regexp
57
+ #
58
+ # A regular expression may be created with:
59
+ #
60
+ # * A regexp literal using slash characters (see [Regexp
61
+ # Literals](rdoc-ref:syntax/literals.rdoc@Regexp+Literals)):
62
+ #
63
+ # # This is a very common usage.
64
+ # /foo/ # => /foo/
65
+ #
66
+ # * A <code>%r</code> regexp literal (see [%r: Regexp
67
+ # Literals](rdoc-ref:syntax/literals.rdoc@25r-3A+Regexp+Literals)):
68
+ #
69
+ # # Same delimiter character at beginning and end;
70
+ # # useful for avoiding escaping characters
71
+ # %r/name\/value pair/ # => /name\/value pair/
72
+ # %r:name/value pair: # => /name\/value pair/
73
+ # %r|name/value pair| # => /name\/value pair/
74
+ #
75
+ # # Certain "paired" characters can be delimiters.
76
+ # %r[foo] # => /foo/
77
+ # %r{foo} # => /foo/
78
+ # %r(foo) # => /foo/
79
+ # %r<foo> # => /foo/
80
+ #
81
+ # * Method Regexp.new.
82
+ #
83
+ # ## Method `match`
84
+ #
85
+ # Each of the methods Regexp#match, String#match, and Symbol#match returns a
86
+ # MatchData object if a match was found, `nil` otherwise; each also sets [global
87
+ # variables](rdoc-ref:Regexp@Global+Variables):
88
+ #
89
+ # 'food'.match(/foo/) # => #<MatchData "foo">
90
+ # 'food'.match(/bar/) # => nil
91
+ #
92
+ # ## Operator <code>=~</code>
93
+ #
94
+ # Each of the operators Regexp#=~, String#=~, and Symbol#=~ returns an integer
95
+ # offset if a match was found, `nil` otherwise; each also sets [global
96
+ # variables](rdoc-ref:Regexp@Global+Variables):
97
+ #
98
+ # /bar/ =~ 'foo bar' # => 4
99
+ # 'foo bar' =~ /bar/ # => 4
100
+ # /baz/ =~ 'foo bar' # => nil
101
+ #
102
+ # ## Method <code>match?</code>
103
+ #
104
+ # Each of the methods Regexp#match?, String#match?, and Symbol#match? returns
105
+ # `true` if a match was found, `false` otherwise; none sets [global
106
+ # variables](rdoc-ref:Regexp@Global+Variables):
107
+ #
108
+ # 'food'.match?(/foo/) # => true
109
+ # 'food'.match?(/bar/) # => false
110
+ #
111
+ # ## Global Variables
112
+ #
113
+ # Certain regexp-oriented methods assign values to global variables:
114
+ #
115
+ # * <code>#match</code>: see [Method match](rdoc-ref:Regexp@Method+match).
116
+ # * <code>#=~</code>: see [Operator =~](rdoc-ref:Regexp@Operator+-3D~).
117
+ #
118
+ # The affected global variables are:
119
+ #
120
+ # * <code>$~</code>: Returns a MatchData object, or `nil`.
121
+ # * <code>$&</code>: Returns the matched part of the string, or `nil`.
122
+ # * <code>$`</code>: Returns the part of the string to the left of the match,
123
+ # or `nil`.
124
+ # * <code>$'</code>: Returns the part of the string to the right of the match,
125
+ # or `nil`.
126
+ # * <code>$+</code>: Returns the last group matched, or `nil`.
127
+ # * <code>$1</code>, <code>$2</code>, etc.: Returns the first, second, etc.,
128
+ # matched group, or `nil`. Note that <code>$0</code> is quite different; it
129
+ # returns the name of the currently executing program.
130
+ #
131
+ # These variables, except for <code>$~</code>, are shorthands for methods of
132
+ # <code>$~</code>. See MatchData@Global+variables+equivalence.
133
+ #
134
+ # Examples:
135
+ #
136
+ # # Matched string, but no matched groups.
137
+ # 'foo bar bar baz'.match('bar')
138
+ # $~ # => #<MatchData "bar">
139
+ # $& # => "bar"
140
+ # $` # => "foo "
141
+ # $' # => " bar baz"
142
+ # $+ # => nil
143
+ # $1 # => nil
144
+ #
145
+ # # Matched groups.
146
+ # /s(\w{2}).*(c)/.match('haystack')
147
+ # $~ # => #<MatchData "stac" 1:"ta" 2:"c">
148
+ # $& # => "stac"
149
+ # $` # => "hay"
150
+ # $' # => "k"
151
+ # $+ # => "c"
152
+ # $1 # => "ta"
153
+ # $2 # => "c"
154
+ # $3 # => nil
155
+ #
156
+ # # No match.
157
+ # 'foo'.match('bar')
158
+ # $~ # => nil
159
+ # $& # => nil
160
+ # $` # => nil
161
+ # $' # => nil
162
+ # $+ # => nil
163
+ # $1 # => nil
164
+ #
165
+ # Note that Regexp#match?, String#match?, and Symbol#match? do not set global
166
+ # variables.
167
+ #
168
+ # ## Sources
169
+ #
170
+ # As seen above, the simplest regexp uses a literal expression as its source:
171
+ #
172
+ # re = /foo/ # => /foo/
173
+ # re.match('food') # => #<MatchData "foo">
174
+ # re.match('good') # => nil
175
+ #
176
+ # A rich collection of available *subexpressions* gives the regexp great power
177
+ # and flexibility:
178
+ #
179
+ # * [Special characters](rdoc-ref:Regexp@Special+Characters)
180
+ # * [Source literals](rdoc-ref:Regexp@Source+Literals)
181
+ # * [Character classes](rdoc-ref:Regexp@Character+Classes)
182
+ # * [Shorthand character classes](rdoc-ref:Regexp@Shorthand+Character+Classes)
183
+ # * [Anchors](rdoc-ref:Regexp@Anchors)
184
+ # * [Alternation](rdoc-ref:Regexp@Alternation)
185
+ # * [Quantifiers](rdoc-ref:Regexp@Quantifiers)
186
+ # * [Groups and captures](rdoc-ref:Regexp@Groups+and+Captures)
187
+ # * [Unicode](rdoc-ref:Regexp@Unicode)
188
+ # * [POSIX Bracket Expressions](rdoc-ref:Regexp@POSIX+Bracket+Expressions)
189
+ # * [Comments](rdoc-ref:Regexp@Comments)
190
+ #
191
+ # ### Special Characters
192
+ #
193
+ # Regexp special characters, called *metacharacters*, have special meanings in
194
+ # certain contexts; depending on the context, these are sometimes
195
+ # metacharacters:
196
+ #
197
+ # . ? - + * ^ \ | $ ( ) [ ] { }
198
+ #
199
+ # To match a metacharacter literally, backslash-escape it:
200
+ #
201
+ # # Matches one or more 'o' characters.
202
+ # /o+/.match('foo') # => #<MatchData "oo">
203
+ # # Would match 'o+'.
204
+ # /o\+/.match('foo') # => nil
205
+ #
206
+ # To match a backslash literally, backslash-escape it:
207
+ #
208
+ # /\./.match('\.') # => #<MatchData ".">
209
+ # /\\./.match('\.') # => #<MatchData "\\.">
210
+ #
211
+ # Method Regexp.escape returns an escaped string:
212
+ #
213
+ # Regexp.escape('.?-+*^\|$()[]{}')
214
+ # # => "\\.\\?\\-\\+\\*\\^\\\\\\|\\$\\(\\)\\[\\]\\{\\}"
215
+ #
216
+ # ### Source Literals
217
+ #
218
+ # The source literal largely behaves like a double-quoted string; see
219
+ # [Double-Quoted String
220
+ # Literals](rdoc-ref:syntax/literals.rdoc@Double-Quoted+String+Literals).
221
+ #
222
+ # In particular, a source literal may contain interpolated expressions:
223
+ #
224
+ # s = 'foo' # => "foo"
225
+ # /#{s}/ # => /foo/
226
+ # /#{s.capitalize}/ # => /Foo/
227
+ # /#{2 + 2}/ # => /4/
228
+ #
229
+ # There are differences between an ordinary string literal and a source literal;
230
+ # see [Shorthand Character
231
+ # Classes](rdoc-ref:Regexp@Shorthand+Character+Classes).
232
+ #
233
+ # * <code>\s</code> in an ordinary string literal is equivalent to a space
234
+ # character; in a source literal, it's shorthand for matching a whitespace
235
+ # character.
236
+ # * In an ordinary string literal, these are (needlessly) escaped characters;
237
+ # in a source literal, they are shorthands for various matching characters:
238
+ #
239
+ # \w \W \d \D \h \H \S \R
240
+ #
241
+ # ### Character Classes
242
+ #
243
+ # A *character class* is delimited by square brackets; it specifies that certain
244
+ # characters match at a given point in the target string:
245
+ #
246
+ # # This character class will match any vowel.
247
+ # re = /B[aeiou]rd/
248
+ # re.match('Bird') # => #<MatchData "Bird">
249
+ # re.match('Bard') # => #<MatchData "Bard">
250
+ # re.match('Byrd') # => nil
251
+ #
252
+ # A character class may contain hyphen characters to specify ranges of
253
+ # characters:
254
+ #
255
+ # # These regexps have the same effect.
256
+ # /[abcdef]/.match('foo') # => #<MatchData "f">
257
+ # /[a-f]/.match('foo') # => #<MatchData "f">
258
+ # /[a-cd-f]/.match('foo') # => #<MatchData "f">
259
+ #
260
+ # When the first character of a character class is a caret (<code>^</code>), the
261
+ # sense of the class is inverted: it matches any character *except* those
262
+ # specified.
263
+ #
264
+ # /[^a-eg-z]/.match('f') # => #<MatchData "f">
265
+ #
266
+ # A character class may contain another character class. By itself this isn't
267
+ # useful because <code>[a-z[0-9]]</code> describes the same set as
268
+ # <code>[a-z0-9]</code>.
269
+ #
270
+ # However, character classes also support the <code>&&</code> operator, which
271
+ # performs set intersection on its arguments. The two can be combined as
272
+ # follows:
273
+ #
274
+ # /[a-w&&[^c-g]z]/ # ([a-w] AND ([^c-g] OR z))
275
+ #
276
+ # This is equivalent to:
277
+ #
278
+ # /[abh-w]/
279
+ #
280
+ # ### Shorthand Character Classes
281
+ #
282
+ # Each of the following metacharacters serves as a shorthand for a character
283
+ # class:
284
+ #
285
+ # * <code>/./</code>: Matches any character except a newline:
286
+ #
287
+ # /./.match('foo') # => #<MatchData "f">
288
+ # /./.match("\n") # => nil
289
+ #
290
+ # * <code>/./m</code>: Matches any character, including a newline; see
291
+ # [Multiline Mode](rdoc-ref:Regexp@Multiline+Mode):
292
+ #
293
+ # /./m.match("\n") # => #<MatchData "\n">
294
+ #
295
+ # * <code>/\w/</code>: Matches a word character: equivalent to
296
+ # <code>[a-zA-Z0-9_]</code>:
297
+ #
298
+ # /\w/.match(' foo') # => #<MatchData "f">
299
+ # /\w/.match(' _') # => #<MatchData "_">
300
+ # /\w/.match(' ') # => nil
301
+ #
302
+ # * <code>/\W/</code>: Matches a non-word character: equivalent to
303
+ # <code>[^a-zA-Z0-9_]</code>:
304
+ #
305
+ # /\W/.match(' ') # => #<MatchData " ">
306
+ # /\W/.match('_') # => nil
307
+ #
308
+ # * <code>/\d/</code>: Matches a digit character: equivalent to
309
+ # <code>[0-9]</code>:
310
+ #
311
+ # /\d/.match('THX1138') # => #<MatchData "1">
312
+ # /\d/.match('foo') # => nil
313
+ #
314
+ # * <code>/\D/</code>: Matches a non-digit character: equivalent to
315
+ # <code>[^0-9]</code>:
316
+ #
317
+ # /\D/.match('123Jump!') # => #<MatchData "J">
318
+ # /\D/.match('123') # => nil
319
+ #
320
+ # * <code>/\h/</code>: Matches a hexdigit character: equivalent to
321
+ # <code>[0-9a-fA-F]</code>:
322
+ #
323
+ # /\h/.match('xyz fedcba9876543210') # => #<MatchData "f">
324
+ # /\h/.match('xyz') # => nil
325
+ #
326
+ # * <code>/\H/</code>: Matches a non-hexdigit character: equivalent to
327
+ # <code>[^0-9a-fA-F]</code>:
328
+ #
329
+ # /\H/.match('fedcba9876543210xyz') # => #<MatchData "x">
330
+ # /\H/.match('fedcba9876543210') # => nil
331
+ #
332
+ # * <code>/\s/</code>: Matches a whitespace character: equivalent to <code>/[
333
+ # \t\r\n\f\v]/</code>:
334
+ #
335
+ # /\s/.match('foo bar') # => #<MatchData " ">
336
+ # /\s/.match('foo') # => nil
337
+ #
338
+ # * <code>/\S/</code>: Matches a non-whitespace character: equivalent to
339
+ # <code>/[^ \t\r\n\f\v]/</code>:
340
+ #
341
+ # /\S/.match(" \t\r\n\f\v foo") # => #<MatchData "f">
342
+ # /\S/.match(" \t\r\n\f\v") # => nil
343
+ #
344
+ # * <code>/\R/</code>: Matches a linebreak, platform-independently:
345
+ #
346
+ # /\R/.match("\r") # => #<MatchData "\r"> # Carriage return (CR)
347
+ # /\R/.match("\n") # => #<MatchData "\n"> # Newline (LF)
348
+ # /\R/.match("\f") # => #<MatchData "\f"> # Formfeed (FF)
349
+ # /\R/.match("\v") # => #<MatchData "\v"> # Vertical tab (VT)
350
+ # /\R/.match("\r\n") # => #<MatchData "\r\n"> # CRLF
351
+ # /\R/.match("\u0085") # => #<MatchData "\u0085"> # Next line (NEL)
352
+ # /\R/.match("\u2028") # => #<MatchData "\u2028"> # Line separator (LSEP)
353
+ # /\R/.match("\u2029") # => #<MatchData "\u2029"> # Paragraph separator (PSEP)
354
+ #
355
+ # ### Anchors
356
+ #
357
+ # An anchor is a metasequence that matches a zero-width position between
358
+ # characters in the target string.
359
+ #
360
+ # For a subexpression with no anchor, matching may begin anywhere in the target
361
+ # string:
362
+ #
363
+ # /real/.match('surrealist') # => #<MatchData "real">
364
+ #
365
+ # For a subexpression with an anchor, matching must begin at the matched anchor.
366
+ #
367
+ # #### Boundary Anchors
368
+ #
369
+ # Each of these anchors matches a boundary:
370
+ #
371
+ # * <code>^</code>: Matches the beginning of a line:
372
+ #
373
+ # /^bar/.match("foo\nbar") # => #<MatchData "bar">
374
+ # /^ar/.match("foo\nbar") # => nil
375
+ #
376
+ # * <code>$</code>: Matches the end of a line:
377
+ #
378
+ # /bar$/.match("foo\nbar") # => #<MatchData "bar">
379
+ # /ba$/.match("foo\nbar") # => nil
380
+ #
381
+ # * <code>\A</code>: Matches the beginning of the string:
382
+ #
383
+ # /\Afoo/.match('foo bar') # => #<MatchData "foo">
384
+ # /\Afoo/.match(' foo bar') # => nil
385
+ #
386
+ # * <code>\Z</code>: Matches the end of the string; if string ends with a
387
+ # single newline, it matches just before the ending newline:
388
+ #
389
+ # /foo\Z/.match('bar foo') # => #<MatchData "foo">
390
+ # /foo\Z/.match('foo bar') # => nil
391
+ # /foo\Z/.match("bar foo\n") # => #<MatchData "foo">
392
+ # /foo\Z/.match("bar foo\n\n") # => nil
393
+ #
394
+ # * <code>\z</code>: Matches the end of the string:
395
+ #
396
+ # /foo\z/.match('bar foo') # => #<MatchData "foo">
397
+ # /foo\z/.match('foo bar') # => nil
398
+ # /foo\z/.match("bar foo\n") # => nil
399
+ #
400
+ # * <code>\b</code>: Matches word boundary when not inside brackets; matches
401
+ # backspace (<code>"0x08"</code>) when inside brackets:
402
+ #
403
+ # /foo\b/.match('foo bar') # => #<MatchData "foo">
404
+ # /foo\b/.match('foobar') # => nil
405
+ #
406
+ # * <code>\B</code>: Matches non-word boundary:
407
+ #
408
+ # /foo\B/.match('foobar') # => #<MatchData "foo">
409
+ # /foo\B/.match('foo bar') # => nil
410
+ #
411
+ # * <code>\G</code>: Matches first matching position:
412
+ #
413
+ # In methods like String#gsub and String#scan, it changes on each iteration.
414
+ # It initially matches the beginning of subject, and in each following
415
+ # iteration it matches where the last match finished.
416
+ #
417
+ # " a b c".gsub(/ /, '_') # => "____a_b_c"
418
+ # " a b c".gsub(/\G /, '_') # => "____a b c"
419
+ #
420
+ # In methods like Regexp#match and String#match that take an optional
421
+ # offset, it matches where the search begins.
422
+ #
423
+ # "hello, world".match(/,/, 3) # => #<MatchData ",">
424
+ # "hello, world".match(/\G,/, 3) # => nil
425
+ #
426
+ # #### Lookaround Anchors
427
+ #
428
+ # Lookahead anchors:
429
+ #
430
+ # * <code>(?=_pat_)</code>: Positive lookahead assertion: ensures that the
431
+ # following characters match *pat*, but doesn't include those characters in
432
+ # the matched substring.
433
+ #
434
+ # * <code>(?!_pat_)</code>: Negative lookahead assertion: ensures that the
435
+ # following characters *do not* match *pat*, but doesn't include those
436
+ # characters in the matched substring.
437
+ #
438
+ # Lookbehind anchors:
439
+ #
440
+ # * <code>(?<=_pat_)</code>: Positive lookbehind assertion: ensures that the
441
+ # preceding characters match *pat*, but doesn't include those characters in
442
+ # the matched substring.
443
+ #
444
+ # * <code>(?<!_pat_)</code>: Negative lookbehind assertion: ensures that the
445
+ # preceding characters do not match *pat*, but doesn't include those
446
+ # characters in the matched substring.
447
+ #
448
+ # The pattern below uses positive lookahead and positive lookbehind to match
449
+ # text appearing in <code><b></code>...<code></b></code> tags without including
450
+ # the tags in the match:
451
+ #
452
+ # /(?<=<b>)\w+(?=<\/b>)/.match("Fortune favors the <b>bold</b>.")
453
+ # # => #<MatchData "bold">
454
+ #
455
+ # The pattern in lookbehind must be fixed-width. But top-level alternatives can
456
+ # be of various lengths. ex. (?<=a|bc) is OK. (?<=aaa(?:b|cd)) is not allowed.
457
+ #
458
+ # #### Match-Reset Anchor
459
+ #
460
+ # * <code>\K</code>: Match reset: the matched content preceding
461
+ # <code>\K</code> in the regexp is excluded from the result. For example,
462
+ # the following two regexps are almost equivalent:
463
+ #
464
+ # /ab\Kc/.match('abc') # => #<MatchData "c">
465
+ # /(?<=ab)c/.match('abc') # => #<MatchData "c">
466
+ #
467
+ # These match same string and <code>$&</code> equals <code>'c'</code>, while
468
+ # the matched position is different.
469
+ #
470
+ # As are the following two regexps:
471
+ #
472
+ # /(a)\K(b)\Kc/
473
+ # /(?<=(?<=(a))(b))c/
474
+ #
475
+ # ### Alternation
476
+ #
477
+ # The vertical bar metacharacter (<code>|</code>) may be used within parentheses
478
+ # to express alternation: two or more subexpressions any of which may match the
479
+ # target string.
480
+ #
481
+ # Two alternatives:
482
+ #
483
+ # re = /(a|b)/
484
+ # re.match('foo') # => nil
485
+ # re.match('bar') # => #<MatchData "b" 1:"b">
486
+ #
487
+ # Four alternatives:
488
+ #
489
+ # re = /(a|b|c|d)/
490
+ # re.match('shazam') # => #<MatchData "a" 1:"a">
491
+ # re.match('cold') # => #<MatchData "c" 1:"c">
492
+ #
493
+ # Each alternative is a subexpression, and may be composed of other
494
+ # subexpressions:
495
+ #
496
+ # re = /([a-c]|[x-z])/
497
+ # re.match('bar') # => #<MatchData "b" 1:"b">
498
+ # re.match('ooz') # => #<MatchData "z" 1:"z">
499
+ #
500
+ # Method Regexp.union provides a convenient way to construct a regexp with
501
+ # alternatives.
502
+ #
503
+ # ### Quantifiers
504
+ #
505
+ # A simple regexp matches one character:
506
+ #
507
+ # /\w/.match('Hello') # => #<MatchData "H">
508
+ #
509
+ # An added *quantifier* specifies how many matches are required or allowed:
510
+ #
511
+ # * <code>*</code> - Matches zero or more times:
512
+ #
513
+ # /\w*/.match('')
514
+ # # => #<MatchData "">
515
+ # /\w*/.match('x')
516
+ # # => #<MatchData "x">
517
+ # /\w*/.match('xyz')
518
+ # # => #<MatchData "xyz">
519
+ #
520
+ # * <code>+</code> - Matches one or more times:
521
+ #
522
+ # /\w+/.match('') # => nil
523
+ # /\w+/.match('x') # => #<MatchData "x">
524
+ # /\w+/.match('xyz') # => #<MatchData "xyz">
525
+ #
526
+ # * <code>?</code> - Matches zero or one times:
527
+ #
528
+ # /\w?/.match('') # => #<MatchData "">
529
+ # /\w?/.match('x') # => #<MatchData "x">
530
+ # /\w?/.match('xyz') # => #<MatchData "x">
531
+ #
532
+ # * <code>{</code>*n*<code>}</code> - Matches exactly *n* times:
533
+ #
534
+ # /\w{2}/.match('') # => nil
535
+ # /\w{2}/.match('x') # => nil
536
+ # /\w{2}/.match('xyz') # => #<MatchData "xy">
537
+ #
538
+ # * <code>{</code>*min*<code>,}</code> - Matches *min* or more times:
539
+ #
540
+ # /\w{2,}/.match('') # => nil
541
+ # /\w{2,}/.match('x') # => nil
542
+ # /\w{2,}/.match('xy') # => #<MatchData "xy">
543
+ # /\w{2,}/.match('xyz') # => #<MatchData "xyz">
544
+ #
545
+ # * <code>{,</code>*max*<code>}</code> - Matches *max* or fewer times:
546
+ #
547
+ # /\w{,2}/.match('') # => #<MatchData "">
548
+ # /\w{,2}/.match('x') # => #<MatchData "x">
549
+ # /\w{,2}/.match('xyz') # => #<MatchData "xy">
550
+ #
551
+ # * <code>{</code>*min*<code>,</code>*max*<code>}</code> - Matches at least
552
+ # *min* times and at most *max* times:
553
+ #
554
+ # /\w{1,2}/.match('') # => nil
555
+ # /\w{1,2}/.match('x') # => #<MatchData "x">
556
+ # /\w{1,2}/.match('xyz') # => #<MatchData "xy">
557
+ #
558
+ # #### Greedy, Lazy, or Possessive Matching
559
+ #
560
+ # Quantifier matching may be greedy, lazy, or possessive:
561
+ #
562
+ # * In *greedy* matching, as many occurrences as possible are matched while
563
+ # still allowing the overall match to succeed. Greedy quantifiers:
564
+ # <code>*</code>, <code>+</code>, <code>?</code>, <code>{min, max}</code>
565
+ # and its variants.
566
+ # * In *lazy* matching, the minimum number of occurrences are matched. Lazy
567
+ # quantifiers: <code>*?</code>, <code>+?</code>, <code>??</code>,
568
+ # <code>{min, max}?</code> and its variants.
569
+ # * In *possessive* matching, once a match is found, there is no backtracking;
570
+ # that match is retained, even if it jeopardises the overall match.
571
+ # Possessive quantifiers: <code>*+</code>, <code>++</code>, <code>?+</code>.
572
+ # Note that <code>{min, max}</code> and its variants do *not* support
573
+ # possessive matching.
574
+ #
575
+ # More:
576
+ #
577
+ # * About greedy and lazy matching, see [Choosing Minimal or Maximal
578
+ # Repetition](https://doc.lagout.org/programmation/Regular%20Expressions/Reg
579
+ # ular%20Expressions%20Cookbook_%20Detailed%20Solutions%20in%20Eight%20Progr
580
+ # amming%20Languages%20%282nd%20ed.%29%20%5BGoyvaerts%20%26%20Levithan%20201
581
+ # 2-09-06%5D.pdf#tutorial-backtrack).
582
+ # * About possessive matching, see [Eliminate Needless
583
+ # Backtracking](https://doc.lagout.org/programmation/Regular%20Expressions/R
584
+ # egular%20Expressions%20Cookbook_%20Detailed%20Solutions%20in%20Eight%20Pro
585
+ # gramming%20Languages%20%282nd%20ed.%29%20%5BGoyvaerts%20%26%20Levithan%202
586
+ # 012-09-06%5D.pdf#tutorial-backtrack).
587
+ #
588
+ # ### Groups and Captures
589
+ #
590
+ # A simple regexp has (at most) one match:
591
+ #
592
+ # re = /\d\d\d\d-\d\d-\d\d/
593
+ # re.match('1943-02-04') # => #<MatchData "1943-02-04">
594
+ # re.match('1943-02-04').size # => 1
595
+ # re.match('foo') # => nil
596
+ #
597
+ # Adding one or more pairs of parentheses, <code>(_subexpression_)</code>,
598
+ # defines *groups*, which may result in multiple matched substrings, called
599
+ # *captures*:
600
+ #
601
+ # re = /(\d\d\d\d)-(\d\d)-(\d\d)/
602
+ # re.match('1943-02-04') # => #<MatchData "1943-02-04" 1:"1943" 2:"02" 3:"04">
603
+ # re.match('1943-02-04').size # => 4
604
+ #
605
+ # The first capture is the entire matched string; the other captures are the
606
+ # matched substrings from the groups.
607
+ #
608
+ # A group may have a [quantifier](rdoc-ref:Regexp@Quantifiers):
609
+ #
610
+ # re = /July 4(th)?/
611
+ # re.match('July 4') # => #<MatchData "July 4" 1:nil>
612
+ # re.match('July 4th') # => #<MatchData "July 4th" 1:"th">
613
+ #
614
+ # re = /(foo)*/
615
+ # re.match('') # => #<MatchData "" 1:nil>
616
+ # re.match('foo') # => #<MatchData "foo" 1:"foo">
617
+ # re.match('foofoo') # => #<MatchData "foofoo" 1:"foo">
618
+ #
619
+ # re = /(foo)+/
620
+ # re.match('') # => nil
621
+ # re.match('foo') # => #<MatchData "foo" 1:"foo">
622
+ # re.match('foofoo') # => #<MatchData "foofoo" 1:"foo">
623
+ #
624
+ # The returned MatchData object gives access to the matched substrings:
625
+ #
626
+ # re = /(\d\d\d\d)-(\d\d)-(\d\d)/
627
+ # md = re.match('1943-02-04')
628
+ # # => #<MatchData "1943-02-04" 1:"1943" 2:"02" 3:"04">
629
+ # md[0] # => "1943-02-04"
630
+ # md[1] # => "1943"
631
+ # md[2] # => "02"
632
+ # md[3] # => "04"
633
+ #
634
+ # #### Non-Capturing Groups
635
+ #
636
+ # A group may be made non-capturing; it is still a group (and, for example, can
637
+ # have a quantifier), but its matching substring is not included among the
638
+ # captures.
639
+ #
640
+ # A non-capturing group begins with <code>?:</code> (inside the parentheses):
641
+ #
642
+ # # Don't capture the year.
643
+ # re = /(?:\d\d\d\d)-(\d\d)-(\d\d)/
644
+ # md = re.match('1943-02-04') # => #<MatchData "1943-02-04" 1:"02" 2:"04">
645
+ #
646
+ # #### Backreferences
647
+ #
648
+ # A group match may also be referenced within the regexp itself; such a
649
+ # reference is called a `backreference`:
650
+ #
651
+ # /[csh](..) [csh]\1 in/.match('The cat sat in the hat')
652
+ # # => #<MatchData "cat sat in" 1:"at">
653
+ #
654
+ # This table shows how each subexpression in the regexp above matches a
655
+ # substring in the target string:
656
+ #
657
+ # | Subexpression in Regexp | Matching Substring in Target String |
658
+ # |---------------------------|-------------------------------------|
659
+ # | First '[csh]' | Character 'c' |
660
+ # | '(..)' | First substring 'at' |
661
+ # | First space ' ' | First space character ' ' |
662
+ # | Second '[csh]' | Character 's' |
663
+ # | '\1' (backreference 'at') | Second substring 'at' |
664
+ # | ' in' | Substring ' in' |
665
+ #
666
+ # A regexp may contain any number of groups:
667
+ #
668
+ # * For a large number of groups:
669
+ #
670
+ # * The ordinary <code>\_n_</code> notation applies only for *n* in range
671
+ # (1..9).
672
+ # * The <code>MatchData[_n_]</code> notation applies for any non-negative
673
+ # *n*.
674
+ #
675
+ # * <code>\0</code> is a special backreference, referring to the entire
676
+ # matched string; it may not be used within the regexp itself, but may be
677
+ # used outside it (for example, in a substitution method call):
678
+ #
679
+ # 'The cat sat in the hat'.gsub(/[csh]at/, '\0s')
680
+ # # => "The cats sats in the hats"
681
+ #
682
+ # #### Named Captures
683
+ #
684
+ # As seen above, a capture can be referred to by its number. A capture can also
685
+ # have a name, prefixed as <code>?<_name_></code> or <code>?'_name_'</code>, and
686
+ # the name (symbolized) may be used as an index in <code>MatchData[]</code>:
687
+ #
688
+ # md = /\$(?<dollars>\d+)\.(?'cents'\d+)/.match("$3.67")
689
+ # # => #<MatchData "$3.67" dollars:"3" cents:"67">
690
+ # md[:dollars] # => "3"
691
+ # md[:cents] # => "67"
692
+ # # The capture numbers are still valid.
693
+ # md[2] # => "67"
694
+ #
695
+ # When a regexp contains a named capture, there are no unnamed captures:
696
+ #
697
+ # /\$(?<dollars>\d+)\.(\d+)/.match("$3.67")
698
+ # # => #<MatchData "$3.67" dollars:"3">
699
+ #
700
+ # A named group may be backreferenced as <code>\k<_name_></code>:
701
+ #
702
+ # /(?<vowel>[aeiou]).\k<vowel>.\k<vowel>/.match('ototomy')
703
+ # # => #<MatchData "ototo" vowel:"o">
704
+ #
705
+ # When (and only when) a regexp contains named capture groups and appears before
706
+ # the <code>=~</code> operator, the captured substrings are assigned to local
707
+ # variables with corresponding names:
708
+ #
709
+ # /\$(?<dollars>\d+)\.(?<cents>\d+)/ =~ '$3.67'
710
+ # dollars # => "3"
711
+ # cents # => "67"
712
+ #
713
+ # Method Regexp#named_captures returns a hash of the capture names and
714
+ # substrings; method Regexp#names returns an array of the capture names.
715
+ #
716
+ # #### Atomic Grouping
717
+ #
718
+ # A group may be made *atomic* with
719
+ # <code>(?></code>*subexpression*<code>)</code>.
720
+ #
721
+ # This causes the subexpression to be matched independently of the rest of the
722
+ # expression, so that the matched substring becomes fixed for the remainder of
723
+ # the match, unless the entire subexpression must be abandoned and subsequently
724
+ # revisited.
725
+ #
726
+ # In this way *subexpression* is treated as a non-divisible whole. Atomic
727
+ # grouping is typically used to optimise patterns to prevent needless
728
+ # backtracking .
729
+ #
730
+ # Example (without atomic grouping):
731
+ #
732
+ # /".*"/.match('"Quote"') # => #<MatchData "\"Quote\"">
733
+ #
734
+ # Analysis:
735
+ #
736
+ # 1. The leading subexpression <code>"</code> in the pattern matches the first
737
+ # character <code>"</code> in the target string.
738
+ # 2. The next subexpression <code>.*</code> matches the next substring
739
+ # <code>Quote"</code> (including the trailing double-quote).
740
+ # 3. Now there is nothing left in the target string to match the trailing
741
+ # subexpression <code>"</code> in the pattern; this would cause the overall
742
+ # match to fail.
743
+ # 4. The matched substring is backtracked by one position: `Quote`.
744
+ # 5. The final subexpression <code>"</code> now matches the final substring
745
+ # <code>"</code>, and the overall match succeeds.
746
+ #
747
+ # If subexpression <code>.*</code> is grouped atomically, the backtracking is
748
+ # disabled, and the overall match fails:
749
+ #
750
+ # /"(?>.*)"/.match('"Quote"') # => nil
751
+ #
752
+ # Atomic grouping can affect performance; see [Atomic
753
+ # Group](https://www.regular-expressions.info/atomic.html).
754
+ #
755
+ # #### Subexpression Calls
756
+ #
757
+ # As seen above, a backreference number (<code>\_n_</code>) or name
758
+ # (<code>\k<_name_></code>) gives access to a captured *substring*; the
759
+ # corresponding regexp *subexpression* may also be accessed, via the number
760
+ # (<code>\g<i>n</i></code>) or name (<code>\g<_name_></code>):
761
+ #
762
+ # /\A(?<paren>\(\g<paren>*\))*\z/.match('(())')
763
+ # # ^1
764
+ # # ^2
765
+ # # ^3
766
+ # # ^4
767
+ # # ^5
768
+ # # ^6
769
+ # # ^7
770
+ # # ^8
771
+ # # ^9
772
+ # # ^10
773
+ #
774
+ # The pattern:
775
+ #
776
+ # 1. Matches at the beginning of the string, i.e. before the first character.
777
+ # 2. Enters a named group `paren`.
778
+ # 3. Matches the first character in the string, <code>'('</code>.
779
+ # 4. Calls the `paren` group again, i.e. recurses back to the second step.
780
+ # 5. Re-enters the `paren` group.
781
+ # 6. Matches the second character in the string, <code>'('</code>.
782
+ # 7. Attempts to call `paren` a third time, but fails because doing so would
783
+ # prevent an overall successful match.
784
+ # 8. Matches the third character in the string, <code>')'</code>; marks the end
785
+ # of the second recursive call
786
+ # 9. Matches the fourth character in the string, <code>')'</code>.
787
+ # 10. Matches the end of the string.
788
+ #
789
+ # See [Subexpression
790
+ # calls](https://learnbyexample.github.io/Ruby_Regexp/groupings-and-backreferenc
791
+ # es.html?highlight=subexpression#subexpression-calls).
792
+ #
793
+ # #### Conditionals
794
+ #
795
+ # The conditional construct takes the form <code>(?(_cond_)_yes_|_no_)</code>,
796
+ # where:
797
+ #
798
+ # * *cond* may be a capture number or name.
799
+ # * The match to be applied is *yes* if *cond* is captured; otherwise the
800
+ # match to be applied is *no*.
801
+ # * If not needed, <code>|_no_</code> may be omitted.
802
+ #
803
+ # Examples:
804
+ #
805
+ # re = /\A(foo)?(?(1)(T)|(F))\z/
806
+ # re.match('fooT') # => #<MatchData "fooT" 1:"foo" 2:"T" 3:nil>
807
+ # re.match('F') # => #<MatchData "F" 1:nil 2:nil 3:"F">
808
+ # re.match('fooF') # => nil
809
+ # re.match('T') # => nil
810
+ #
811
+ # re = /\A(?<xyzzy>foo)?(?(<xyzzy>)(T)|(F))\z/
812
+ # re.match('fooT') # => #<MatchData "fooT" xyzzy:"foo">
813
+ # re.match('F') # => #<MatchData "F" xyzzy:nil>
814
+ # re.match('fooF') # => nil
815
+ # re.match('T') # => nil
816
+ #
817
+ # #### Absence Operator
818
+ #
819
+ # The absence operator is a special group that matches anything which does *not*
820
+ # match the contained subexpressions.
821
+ #
822
+ # /(?~real)/.match('surrealist') # => #<MatchData "surrea">
823
+ # /(?~real)ist/.match('surrealist') # => #<MatchData "ealist">
824
+ # /sur(?~real)ist/.match('surrealist') # => nil
825
+ #
826
+ # ### Unicode
827
+ #
828
+ # #### Unicode Properties
829
+ #
830
+ # The <code>/\p{_property_name_}/</code> construct (with lowercase `p`) matches
831
+ # characters using a Unicode property name, much like a character class;
832
+ # property `Alpha` specifies alphabetic characters:
833
+ #
834
+ # /\p{Alpha}/.match('a') # => #<MatchData "a">
835
+ # /\p{Alpha}/.match('1') # => nil
836
+ #
837
+ # A property can be inverted by prefixing the name with a caret character
838
+ # (<code>^</code>):
839
+ #
840
+ # /\p{^Alpha}/.match('1') # => #<MatchData "1">
841
+ # /\p{^Alpha}/.match('a') # => nil
842
+ #
843
+ # Or by using <code>\P</code> (uppercase `P`):
844
+ #
845
+ # /\P{Alpha}/.match('1') # => #<MatchData "1">
846
+ # /\P{Alpha}/.match('a') # => nil
847
+ #
848
+ # See [Unicode Properties](rdoc-ref:language/regexp/unicode_properties.rdoc) for
849
+ # regexps based on the numerous properties.
850
+ #
851
+ # Some commonly-used properties correspond to POSIX bracket expressions:
852
+ #
853
+ # * <code>/\p{Alnum}/</code>: Alphabetic and numeric character
854
+ # * <code>/\p{Alpha}/</code>: Alphabetic character
855
+ # * <code>/\p{Blank}/</code>: Space or tab
856
+ # * <code>/\p{Cntrl}/</code>: Control character
857
+ # * <code>/\p{Digit}/</code>: Digit characters, and similar)
858
+ # * <code>/\p{Lower}/</code>: Lowercase alphabetical character
859
+ # * <code>/\p{Print}/</code>: Like <code>\p{Graph}</code>, but includes the
860
+ # space character
861
+ # * <code>/\p{Punct}/</code>: Punctuation character
862
+ # * <code>/\p{Space}/</code>: Whitespace character (<code>[:blank:]</code>,
863
+ # newline, carriage return, etc.)
864
+ # * <code>/\p{Upper}/</code>: Uppercase alphabetical
865
+ # * <code>/\p{XDigit}/</code>: Digit allowed in a hexadecimal number (i.e.,
866
+ # 0-9a-fA-F)
867
+ #
868
+ # These are also commonly used:
869
+ #
870
+ # * <code>/\p{Emoji}/</code>: Unicode emoji.
871
+ # * <code>/\p{Graph}/</code>: Characters excluding <code>/\p{Cntrl}/</code>
872
+ # and <code>/\p{Space}/</code>. Note that invisible characters under the
873
+ # Unicode ["Format"](https://www.compart.com/en/unicode/category/Cf)
874
+ # category are included.
875
+ # * <code>/\p{Word}/</code>: A member in one of these Unicode character
876
+ # categories (see below) or having one of these Unicode properties:
877
+ #
878
+ # * Unicode categories:
879
+ # * `Mark` (`M`).
880
+ # * `Decimal Number` (`Nd`)
881
+ # * `Connector Punctuation` (`Pc`).
882
+ #
883
+ # * Unicode properties:
884
+ # * `Alpha`
885
+ # * `Join_Control`
886
+ #
887
+ # * <code>/\p{ASCII}/</code>: A character in the ASCII character set.
888
+ # * <code>/\p{Any}/</code>: Any Unicode character (including unassigned
889
+ # characters).
890
+ # * <code>/\p{Assigned}/</code>: An assigned character.
891
+ #
892
+ # #### Unicode Character Categories
893
+ #
894
+ # A Unicode character category name:
895
+ #
896
+ # * May be either its full name or its abbreviated name.
897
+ # * Is case-insensitive.
898
+ # * Treats a space, a hyphen, and an underscore as equivalent.
899
+ #
900
+ # Examples:
901
+ #
902
+ # /\p{lu}/ # => /\p{lu}/
903
+ # /\p{LU}/ # => /\p{LU}/
904
+ # /\p{Uppercase Letter}/ # => /\p{Uppercase Letter}/
905
+ # /\p{Uppercase_Letter}/ # => /\p{Uppercase_Letter}/
906
+ # /\p{UPPERCASE-LETTER}/ # => /\p{UPPERCASE-LETTER}/
907
+ #
908
+ # Below are the Unicode character category abbreviations and names. Enumerations
909
+ # of characters in each category are at the links.
910
+ #
911
+ # Letters:
912
+ #
913
+ # * `L`, `Letter`: `LC`, `Lm`, or `Lo`.
914
+ # * `LC`, `Cased_Letter`: `Ll`, `Lt`, or `Lu`.
915
+ # * [Lu, Lowercase_Letter](https://www.compart.com/en/unicode/category/Ll).
916
+ # * [Lu, Modifier_Letter](https://www.compart.com/en/unicode/category/Lm).
917
+ # * [Lu, Other_Letter](https://www.compart.com/en/unicode/category/Lo).
918
+ # * [Lu, Titlecase_Letter](https://www.compart.com/en/unicode/category/Lt).
919
+ # * [Lu, Uppercase_Letter](https://www.compart.com/en/unicode/category/Lu).
920
+ #
921
+ # Marks:
922
+ #
923
+ # * `M`, `Mark`: `Mc`, `Me`, or `Mn`.
924
+ # * [Mc, Spacing_Mark](https://www.compart.com/en/unicode/category/Mc).
925
+ # * [Me, Enclosing_Mark](https://www.compart.com/en/unicode/category/Me).
926
+ # * [Mn, Nonapacing_Mark](https://www.compart.com/en/unicode/category/Mn).
927
+ #
928
+ # Numbers:
929
+ #
930
+ # * `N`, `Number`: `Nd`, `Nl`, or `No`.
931
+ # * [Nd, Decimal_Number](https://www.compart.com/en/unicode/category/Nd).
932
+ # * [Nl, Letter_Number](https://www.compart.com/en/unicode/category/Nl).
933
+ # * [No, Other_Number](https://www.compart.com/en/unicode/category/No).
934
+ #
935
+ # Punctuation:
936
+ #
937
+ # * `P`, `Punctuation`: `Pc`, `Pd`, `Pe`, `Pf`, `Pi`, `Po`, or `Ps`.
938
+ # * [Pc,
939
+ # Connector_Punctuation](https://www.compart.com/en/unicode/category/Pc).
940
+ # * [Pd, Dash_Punctuation](https://www.compart.com/en/unicode/category/Pd).
941
+ # * [Pe, Close_Punctuation](https://www.compart.com/en/unicode/category/Pe).
942
+ # * [Pf, Final_Punctuation](https://www.compart.com/en/unicode/category/Pf).
943
+ # * [Pi, Initial_Punctuation](https://www.compart.com/en/unicode/category/Pi).
944
+ # * [Po, Other_Punctuation](https://www.compart.com/en/unicode/category/Po).
945
+ # * [Ps, Open_Punctuation](https://www.compart.com/en/unicode/category/Ps).
946
+ #
947
+ # * `S`, `Symbol`: `Sc`, `Sk`, `Sm`, or `So`.
948
+ # * [Sc, Currency_Symbol](https://www.compart.com/en/unicode/category/Sc).
949
+ # * [Sk, Modifier_Symbol](https://www.compart.com/en/unicode/category/Sk).
950
+ # * [Sm, Math_Symbol](https://www.compart.com/en/unicode/category/Sm).
951
+ # * [So, Other_Symbol](https://www.compart.com/en/unicode/category/So).
952
+ #
953
+ # * `Z`, `Separator`: `Zl`, `Zp`, or `Zs`.
954
+ # * [Zl, Line_Separator](https://www.compart.com/en/unicode/category/Zl).
955
+ # * [Zp, Paragraph_Separator](https://www.compart.com/en/unicode/category/Zp).
956
+ # * [Zs, Space_Separator](https://www.compart.com/en/unicode/category/Zs).
957
+ #
958
+ # * `C`, `Other`: `Cc`, `Cf`, `Cn`, `Co`, or `Cs`.
959
+ # * [Cc, Control](https://www.compart.com/en/unicode/category/Cc).
960
+ # * [Cf, Format](https://www.compart.com/en/unicode/category/Cf).
961
+ # * [Cn, Unassigned](https://www.compart.com/en/unicode/category/Cn).
962
+ # * [Co, Private_Use](https://www.compart.com/en/unicode/category/Co).
963
+ # * [Cs, Surrogate](https://www.compart.com/en/unicode/category/Cs).
964
+ #
965
+ # #### Unicode Scripts and Blocks
966
+ #
967
+ # Among the Unicode properties are:
968
+ #
969
+ # * [Unicode scripts](https://en.wikipedia.org/wiki/Script_(Unicode)); see
970
+ # [supported scripts](https://www.unicode.org/standard/supported.html).
971
+ # * [Unicode blocks](https://en.wikipedia.org/wiki/Unicode_block); see
972
+ # [supported blocks](http://www.unicode.org/Public/UNIDATA/Blocks.txt).
973
+ #
974
+ # ### POSIX Bracket Expressions
975
+ #
976
+ # A POSIX *bracket expression* is also similar to a character class. These
977
+ # expressions provide a portable alternative to the above, with the added
978
+ # benefit of encompassing non-ASCII characters:
979
+ #
980
+ # * <code>/\d/</code> matches only ASCII decimal digits `0` through `9`.
981
+ # * <code>/[[:digit:]]/</code> matches any character in the Unicode `Decimal
982
+ # Number` (`Nd`) category; see below.
983
+ #
984
+ # The POSIX bracket expressions:
985
+ #
986
+ # * <code>/[[:digit:]]/</code>: Matches a [Unicode
987
+ # digit](https://www.compart.com/en/unicode/category/Nd):
988
+ #
989
+ # /[[:digit:]]/.match('9') # => #<MatchData "9">
990
+ # /[[:digit:]]/.match("\u1fbf9") # => #<MatchData "9">
991
+ #
992
+ # * <code>/[[:xdigit:]]/</code>: Matches a digit allowed in a hexadecimal
993
+ # number; equivalent to <code>[0-9a-fA-F]</code>.
994
+ #
995
+ # * <code>/[[:upper:]]/</code>: Matches a [Unicode uppercase
996
+ # letter](https://www.compart.com/en/unicode/category/Lu):
997
+ #
998
+ # /[[:upper:]]/.match('A') # => #<MatchData "A">
999
+ # /[[:upper:]]/.match("\u00c6") # => #<MatchData "Æ">
1000
+ #
1001
+ # * <code>/[[:lower:]]/</code>: Matches a [Unicode lowercase
1002
+ # letter](https://www.compart.com/en/unicode/category/Ll):
1003
+ #
1004
+ # /[[:lower:]]/.match('a') # => #<MatchData "a">
1005
+ # /[[:lower:]]/.match("\u01fd") # => #<MatchData "ǽ">
1006
+ #
1007
+ # * <code>/[[:alpha:]]/</code>: Matches <code>/[[:upper:]]/</code> or
1008
+ # <code>/[[:lower:]]/</code>.
1009
+ #
1010
+ # * <code>/[[:alnum:]]/</code>: Matches <code>/[[:alpha:]]/</code> or
1011
+ # <code>/[[:digit:]]/</code>.
1012
+ #
1013
+ # * <code>/[[:space:]]/</code>: Matches [Unicode space
1014
+ # character](https://www.compart.com/en/unicode/category/Zs):
1015
+ #
1016
+ # /[[:space:]]/.match(' ') # => #<MatchData " ">
1017
+ # /[[:space:]]/.match("\u2005") # => #<MatchData " ">
1018
+ #
1019
+ # * <code>/[[:blank:]]/</code>: Matches <code>/[[:space:]]/</code> or tab
1020
+ # character:
1021
+ #
1022
+ # /[[:blank:]]/.match(' ') # => #<MatchData " ">
1023
+ # /[[:blank:]]/.match("\u2005") # => #<MatchData " ">
1024
+ # /[[:blank:]]/.match("\t") # => #<MatchData "\t">
1025
+ #
1026
+ # * <code>/[[:cntrl:]]/</code>: Matches [Unicode control
1027
+ # character](https://www.compart.com/en/unicode/category/Cc):
1028
+ #
1029
+ # /[[:cntrl:]]/.match("\u0000") # => #<MatchData "\u0000">
1030
+ # /[[:cntrl:]]/.match("\u009f") # => #<MatchData "\u009F">
1031
+ #
1032
+ # * <code>/[[:graph:]]/</code>: Matches any character except
1033
+ # <code>/[[:space:]]/</code> or <code>/[[:cntrl:]]/</code>.
1034
+ #
1035
+ # * <code>/[[:print:]]/</code>: Matches <code>/[[:graph:]]/</code> or space
1036
+ # character.
1037
+ #
1038
+ # * <code>/[[:punct:]]/</code>: Matches any (Unicode punctuation
1039
+ # character}[https://www.compart.com/en/unicode/category/Po]:
1040
+ #
1041
+ # Ruby also supports these (non-POSIX) bracket expressions:
1042
+ #
1043
+ # * <code>/[[:ascii:]]/</code>: Matches a character in the ASCII character
1044
+ # set.
1045
+ # * <code>/[[:word:]]/</code>: Matches a character in one of these Unicode
1046
+ # character categories or having one of these Unicode properties:
1047
+ #
1048
+ # * Unicode categories:
1049
+ # * `Mark` (`M`).
1050
+ # * `Decimal Number` (`Nd`)
1051
+ # * `Connector Punctuation` (`Pc`).
1052
+ #
1053
+ # * Unicode properties:
1054
+ # * `Alpha`
1055
+ # * `Join_Control`
1056
+ #
1057
+ # ### Comments
1058
+ #
1059
+ # A comment may be included in a regexp pattern using the
1060
+ # <code>(?#</code>*comment*<code>)</code> construct, where *comment* is a
1061
+ # substring that is to be ignored. arbitrary text ignored by the regexp engine:
1062
+ #
1063
+ # /foo(?#Ignore me)bar/.match('foobar') # => #<MatchData "foobar">
1064
+ #
1065
+ # The comment may not include an unescaped terminator character.
1066
+ #
1067
+ # See also [Extended Mode](rdoc-ref:Regexp@Extended+Mode).
1068
+ #
1069
+ # ## Modes
1070
+ #
1071
+ # Each of these modifiers sets a mode for the regexp:
1072
+ #
1073
+ # * `i`: <code>/_pattern_/i</code> sets [Case-Insensitive
1074
+ # Mode](rdoc-ref:Regexp@Case-Insensitive+Mode).
1075
+ # * `m`: <code>/_pattern_/m</code> sets [Multiline
1076
+ # Mode](rdoc-ref:Regexp@Multiline+Mode).
1077
+ # * `x`: <code>/_pattern_/x</code> sets [Extended
1078
+ # Mode](rdoc-ref:Regexp@Extended+Mode).
1079
+ # * `o`: <code>/_pattern_/o</code> sets [Interpolation
1080
+ # Mode](rdoc-ref:Regexp@Interpolation+Mode).
1081
+ #
1082
+ # Any, all, or none of these may be applied.
1083
+ #
1084
+ # Modifiers `i`, `m`, and `x` may be applied to subexpressions:
1085
+ #
1086
+ # * <code>(?_modifier_)</code> turns the mode "on" for ensuing subexpressions
1087
+ # * <code>(?-_modifier_)</code> turns the mode "off" for ensuing
1088
+ # subexpressions
1089
+ # * <code>(?_modifier_:_subexp_)</code> turns the mode "on" for *subexp*
1090
+ # within the group
1091
+ # * <code>(?-_modifier_:_subexp_)</code> turns the mode "off" for *subexp*
1092
+ # within the group
1093
+ #
1094
+ # Example:
1095
+ #
1096
+ # re = /(?i)te(?-i)st/
1097
+ # re.match('test') # => #<MatchData "test">
1098
+ # re.match('TEst') # => #<MatchData "TEst">
1099
+ # re.match('TEST') # => nil
1100
+ # re.match('teST') # => nil
1101
+ #
1102
+ # re = /t(?i:e)st/
1103
+ # re.match('test') # => #<MatchData "test">
1104
+ # re.match('tEst') # => #<MatchData "tEst">
1105
+ # re.match('tEST') # => nil
1106
+ #
1107
+ # Method Regexp#options returns an integer whose value showing the settings for
1108
+ # case-insensitivity mode, multiline mode, and extended mode.
1109
+ #
1110
+ # ### Case-Insensitive Mode
1111
+ #
1112
+ # By default, a regexp is case-sensitive:
1113
+ #
1114
+ # /foo/.match('FOO') # => nil
1115
+ #
1116
+ # Modifier `i` enables case-insensitive mode:
1117
+ #
1118
+ # /foo/i.match('FOO')
1119
+ # # => #<MatchData "FOO">
1120
+ #
1121
+ # Method Regexp#casefold? returns whether the mode is case-insensitive.
1122
+ #
1123
+ # ### Multiline Mode
1124
+ #
1125
+ # The multiline-mode in Ruby is what is commonly called a "dot-all mode":
1126
+ #
1127
+ # * Without the `m` modifier, the subexpression <code>.</code> does not match
1128
+ # newlines:
1129
+ #
1130
+ # /a.c/.match("a\nc") # => nil
1131
+ #
1132
+ # * With the modifier, it does match:
1133
+ #
1134
+ # /a.c/m.match("a\nc") # => #<MatchData "a\nc">
1135
+ #
1136
+ # Unlike other languages, the modifier `m` does not affect the anchors
1137
+ # <code>^</code> and <code>$</code>. These anchors always match at
1138
+ # line-boundaries in Ruby.
1139
+ #
1140
+ # ### Extended Mode
1141
+ #
1142
+ # Modifier `x` enables extended mode, which means that:
1143
+ #
1144
+ # * Literal white space in the pattern is to be ignored.
1145
+ # * Character <code>#</code> marks the remainder of its containing line as a
1146
+ # comment, which is also to be ignored for matching purposes.
1147
+ #
1148
+ # In extended mode, whitespace and comments may be used to form a
1149
+ # self-documented regexp.
1150
+ #
1151
+ # Regexp not in extended mode (matches some Roman numerals):
1152
+ #
1153
+ # pattern = '^M{0,3}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})$'
1154
+ # re = /#{pattern}/
1155
+ # re.match('MCMXLIII') # => #<MatchData "MCMXLIII" 1:"CM" 2:"XL" 3:"III">
1156
+ #
1157
+ # Regexp in extended mode:
1158
+ #
1159
+ # pattern = <<-EOT
1160
+ # ^ # beginning of string
1161
+ # M{0,3} # thousands - 0 to 3 Ms
1162
+ # (CM|CD|D?C{0,3}) # hundreds - 900 (CM), 400 (CD), 0-300 (0 to 3 Cs),
1163
+ # # or 500-800 (D, followed by 0 to 3 Cs)
1164
+ # (XC|XL|L?X{0,3}) # tens - 90 (XC), 40 (XL), 0-30 (0 to 3 Xs),
1165
+ # # or 50-80 (L, followed by 0 to 3 Xs)
1166
+ # (IX|IV|V?I{0,3}) # ones - 9 (IX), 4 (IV), 0-3 (0 to 3 Is),
1167
+ # # or 5-8 (V, followed by 0 to 3 Is)
1168
+ # $ # end of string
1169
+ # EOT
1170
+ # re = /#{pattern}/x
1171
+ # re.match('MCMXLIII') # => #<MatchData "MCMXLIII" 1:"CM" 2:"XL" 3:"III">
1172
+ #
1173
+ # ### Interpolation Mode
1174
+ #
1175
+ # Modifier `o` means that the first time a literal regexp with interpolations is
1176
+ # encountered, the generated Regexp object is saved and used for all future
1177
+ # evaluations of that literal regexp. Without modifier `o`, the generated Regexp
1178
+ # is not saved, so each evaluation of the literal regexp generates a new Regexp
1179
+ # object.
1180
+ #
1181
+ # Without modifier `o`:
1182
+ #
1183
+ # def letters; sleep 5; /[A-Z][a-z]/; end
1184
+ # words = %w[abc def xyz]
1185
+ # start = Time.now
1186
+ # words.each {|word| word.match(/\A[#{letters}]+\z/) }
1187
+ # Time.now - start # => 15.0174892
1188
+ #
1189
+ # With modifier `o`:
1190
+ #
1191
+ # start = Time.now
1192
+ # words.each {|word| word.match(/\A[#{letters}]+\z/o) }
1193
+ # Time.now - start # => 5.0010866
1194
+ #
1195
+ # Note that if the literal regexp does not have interpolations, the `o` behavior
1196
+ # is the default.
1197
+ #
1198
+ # ## Encodings
1199
+ #
1200
+ # By default, a regexp with only US-ASCII characters has US-ASCII encoding:
1201
+ #
1202
+ # re = /foo/
1203
+ # re.source.encoding # => #<Encoding:US-ASCII>
1204
+ # re.encoding # => #<Encoding:US-ASCII>
1205
+ #
1206
+ # A regular expression containing non-US-ASCII characters is assumed to use the
1207
+ # source encoding. This can be overridden with one of the following modifiers.
1208
+ #
1209
+ # * <code>/_pat_/n</code>: US-ASCII if only containing US-ASCII characters,
1210
+ # otherwise ASCII-8BIT:
1211
+ #
1212
+ # /foo/n.encoding # => #<Encoding:US-ASCII>
1213
+ # /foo\xff/n.encoding # => #<Encoding:ASCII-8BIT>
1214
+ # /foo\x7f/n.encoding # => #<Encoding:US-ASCII>
1215
+ #
1216
+ # * <code>/_pat_/u</code>: UTF-8
1217
+ #
1218
+ # /foo/u.encoding # => #<Encoding:UTF-8>
1219
+ #
1220
+ # * <code>/_pat_/e</code>: EUC-JP
1221
+ #
1222
+ # /foo/e.encoding # => #<Encoding:EUC-JP>
1223
+ #
1224
+ # * <code>/_pat_/s</code>: Windows-31J
1225
+ #
1226
+ # /foo/s.encoding # => #<Encoding:Windows-31J>
1227
+ #
1228
+ # A regexp can be matched against a target string when either:
1229
+ #
1230
+ # * They have the same encoding.
1231
+ # * The regexp's encoding is a fixed encoding and the string contains only
1232
+ # ASCII characters. Method Regexp#fixed_encoding? returns whether the regexp
1233
+ # has a *fixed* encoding.
1234
+ #
1235
+ # If a match between incompatible encodings is attempted an
1236
+ # <code>Encoding::CompatibilityError</code> exception is raised.
1237
+ #
1238
+ # Example:
1239
+ #
1240
+ # re = eval("# encoding: ISO-8859-1\n/foo\\xff?/")
1241
+ # re.encoding # => #<Encoding:ISO-8859-1>
1242
+ # re =~ "foo".encode("UTF-8") # => 0
1243
+ # re =~ "foo\u0100" # Raises Encoding::CompatibilityError
1244
+ #
1245
+ # The encoding may be explicitly fixed by including Regexp::FIXEDENCODING in the
1246
+ # second argument for Regexp.new:
1247
+ #
1248
+ # # Regexp with encoding ISO-8859-1.
1249
+ # re = Regexp.new("a".force_encoding('iso-8859-1'), Regexp::FIXEDENCODING)
1250
+ # re.encoding # => #<Encoding:ISO-8859-1>
1251
+ # # Target string with encoding UTF-8.
1252
+ # s = "a\u3042"
1253
+ # s.encoding # => #<Encoding:UTF-8>
1254
+ # re.match(s) # Raises Encoding::CompatibilityError.
1255
+ #
1256
+ # ## Timeouts
1257
+ #
1258
+ # When either a regexp source or a target string comes from untrusted input,
1259
+ # malicious values could become a denial-of-service attack; to prevent such an
1260
+ # attack, it is wise to set a timeout.
1261
+ #
1262
+ # Regexp has two timeout values:
1263
+ #
1264
+ # * A class default timeout, used for a regexp whose instance timeout is
1265
+ # `nil`; this default is initially `nil`, and may be set by method
1266
+ # Regexp.timeout=:
1267
+ #
1268
+ # Regexp.timeout # => nil
1269
+ # Regexp.timeout = 3.0
1270
+ # Regexp.timeout # => 3.0
1271
+ #
1272
+ # * An instance timeout, which defaults to `nil` and may be set in Regexp.new:
1273
+ #
1274
+ # re = Regexp.new('foo', timeout: 5.0)
1275
+ # re.timeout # => 5.0
1276
+ #
1277
+ # When regexp.timeout is `nil`, the timeout "falls through" to Regexp.timeout;
1278
+ # when regexp.timeout is non-`nil`, that value controls timing out:
1279
+ #
1280
+ # | regexp.timeout Value | Regexp.timeout Value | Result |
1281
+ # |----------------------|----------------------|-----------------------------|
1282
+ # | nil | nil | Never times out. |
1283
+ # | nil | Float | Times out in Float seconds. |
1284
+ # | Float | Any | Times out in Float seconds. |
1285
+ #
1286
+ # ## Optimization
1287
+ #
1288
+ # For certain values of the pattern and target string, matching time can grow
1289
+ # polynomially or exponentially in relation to the input size; the potential
1290
+ # vulnerability arising from this is the [regular expression
1291
+ # denial-of-service](https://en.wikipedia.org/wiki/ReDoS) (ReDoS) attack.
1292
+ #
1293
+ # Regexp matching can apply an optimization to prevent ReDoS attacks. When the
1294
+ # optimization is applied, matching time increases linearly (not polynomially or
1295
+ # exponentially) in relation to the input size, and a ReDoS attack is not
1296
+ # possible.
1297
+ #
1298
+ # This optimization is applied if the pattern meets these criteria:
1299
+ #
1300
+ # * No backreferences.
1301
+ # * No subexpression calls.
1302
+ # * No nested lookaround anchors or atomic groups.
1303
+ # * No nested quantifiers with counting (i.e. no nested <code>{n}</code>,
1304
+ # <code>{min,}</code>, <code>{,max}</code>, or <code>{min,max}</code> style
1305
+ # quantifiers)
1306
+ #
1307
+ # You can use method Regexp.linear_time? to determine whether a pattern meets
1308
+ # these criteria:
1309
+ #
1310
+ # Regexp.linear_time?(/a*/) # => true
1311
+ # Regexp.linear_time?('a*') # => true
1312
+ # Regexp.linear_time?(/(a*)\1/) # => false
1313
+ #
1314
+ # However, an untrusted source may not be safe even if the method returns
1315
+ # `true`, because the optimization uses memoization (which may invoke large
1316
+ # memory consumption).
1317
+ #
1318
+ # ## References
1319
+ #
1320
+ # Read:
1321
+ #
1322
+ # * *Mastering Regular Expressions* by Jeffrey E.F. Friedl.
1323
+ # * *Regular Expressions Cookbook* by Jan Goyvaerts & Steven Levithan.
1324
+ #
1325
+ # Explore, test:
1326
+ #
1327
+ # * [Rubular](https://rubular.com/): interactive online editor.
1328
+ #
1329
+ class Regexp
1330
+ # Represents an object's ability to be converted to a `Regexp`.
1331
+ #
1332
+ # This is only used in `Regexp.try_convert` and `Regexp.union` within the standard library.
1333
+ interface _ToRegexp
1334
+ # Converts `self` to a `Regexp`.
1335
+ def to_regexp: () -> Regexp
1336
+ end
1337
+
1338
+ # <!-- rdoc-file=re.c -->
1339
+ # Raised when regexp matching timed out.
1340
+ #
1341
+ class TimeoutError < RegexpError
1342
+ end
1343
+
1344
+ # <!-- rdoc-file=re.c -->
1345
+ # see Regexp.options and Regexp.new
1346
+ #
1347
+ EXTENDED: Integer
1348
+
1349
+ # <!-- rdoc-file=re.c -->
1350
+ # see Regexp.options and Regexp.new
1351
+ #
1352
+ FIXEDENCODING: Integer
1353
+
1354
+ # <!-- rdoc-file=re.c -->
1355
+ # see Regexp.options and Regexp.new
1356
+ #
1357
+ IGNORECASE: Integer
1358
+
1359
+ # <!-- rdoc-file=re.c -->
1360
+ # see Regexp.options and Regexp.new
1361
+ #
1362
+ MULTILINE: Integer
1363
+
1364
+ # <!-- rdoc-file=re.c -->
1365
+ # see Regexp.options and Regexp.new
1366
+ #
1367
+ NOENCODING: Integer
1368
+
1369
+ # <!--
1370
+ # rdoc-file=re.c
1371
+ # - compile(*args)
1372
+ # -->
1373
+ # Alias for Regexp.new
1374
+ #
1375
+ alias self.compile self.new
1376
+
1377
+ # <!--
1378
+ # rdoc-file=re.c
1379
+ # - Regexp.escape(string) -> new_string
1380
+ # -->
1381
+ # Returns a new string that escapes any characters that have special meaning in
1382
+ # a regular expression:
1383
+ #
1384
+ # s = Regexp.escape('\*?{}.') # => "\\\\\\*\\?\\{\\}\\."
1385
+ #
1386
+ # For any string `s`, this call returns a MatchData object:
1387
+ #
1388
+ # r = Regexp.new(Regexp.escape(s)) # => /\\\\\\\*\\\?\\\{\\\}\\\./
1389
+ # r.match(s) # => #<MatchData "\\\\\\*\\?\\{\\}\\.">
1390
+ #
1391
+ def self.escape: (interned str) -> String
1392
+
1393
+ # <!--
1394
+ # rdoc-file=re.c
1395
+ # - Regexp.last_match -> matchdata or nil
1396
+ # - Regexp.last_match(n) -> string or nil
1397
+ # - Regexp.last_match(name) -> string or nil
1398
+ # -->
1399
+ # With no argument, returns the value of <code>$~</code>, which is the result of
1400
+ # the most recent pattern match (see [Regexp global
1401
+ # variables](rdoc-ref:Regexp@Global+Variables)):
1402
+ #
1403
+ # /c(.)t/ =~ 'cat' # => 0
1404
+ # Regexp.last_match # => #<MatchData "cat" 1:"a">
1405
+ # /a/ =~ 'foo' # => nil
1406
+ # Regexp.last_match # => nil
1407
+ #
1408
+ # With non-negative integer argument `n`, returns the _n_th field in the
1409
+ # matchdata, if any, or nil if none:
1410
+ #
1411
+ # /c(.)t/ =~ 'cat' # => 0
1412
+ # Regexp.last_match(0) # => "cat"
1413
+ # Regexp.last_match(1) # => "a"
1414
+ # Regexp.last_match(2) # => nil
1415
+ #
1416
+ # With negative integer argument `n`, counts backwards from the last field:
1417
+ #
1418
+ # Regexp.last_match(-1) # => "a"
1419
+ #
1420
+ # With string or symbol argument `name`, returns the string value for the named
1421
+ # capture, if any:
1422
+ #
1423
+ # /(?<lhs>\w+)\s*=\s*(?<rhs>\w+)/ =~ 'var = val'
1424
+ # Regexp.last_match # => #<MatchData "var = val" lhs:"var"rhs:"val">
1425
+ # Regexp.last_match(:lhs) # => "var"
1426
+ # Regexp.last_match('rhs') # => "val"
1427
+ # Regexp.last_match('foo') # Raises IndexError.
1428
+ #
1429
+ def self.last_match: () -> MatchData?
1430
+ | (MatchData::capture capture) -> String?
1431
+
1432
+ # <!--
1433
+ # rdoc-file=re.c
1434
+ # - Regexp.linear_time?(re)
1435
+ # - Regexp.linear_time?(string, options = 0)
1436
+ # -->
1437
+ # Returns `true` if matching against `re` can be done in linear time to the
1438
+ # input string.
1439
+ #
1440
+ # Regexp.linear_time?(/re/) # => true
1441
+ #
1442
+ # Note that this is a property of the ruby interpreter, not of the argument
1443
+ # regular expression. Identical regexp can or cannot run in linear time
1444
+ # depending on your ruby binary. Neither forward nor backward compatibility is
1445
+ # guaranteed about the return value of this method. Our current algorithm is
1446
+ # (*1) but this is subject to change in the future. Alternative implementations
1447
+ # can also behave differently. They might always return false for everything.
1448
+ #
1449
+ # (*1): https://doi.org/10.1109/SP40001.2021.00032
1450
+ #
1451
+ def self.linear_time?: (Regexp regex, ?nil, ?timeout: untyped) -> bool
1452
+ | (string regex, ?int | string | bool | nil options, ?timeout: untyped) -> bool
1453
+
1454
+ # <!--
1455
+ # rdoc-file=re.c
1456
+ # - Regexp.escape(string) -> new_string
1457
+ # -->
1458
+ # Returns a new string that escapes any characters that have special meaning in
1459
+ # a regular expression:
1460
+ #
1461
+ # s = Regexp.escape('\*?{}.') # => "\\\\\\*\\?\\{\\}\\."
1462
+ #
1463
+ # For any string `s`, this call returns a MatchData object:
1464
+ #
1465
+ # r = Regexp.new(Regexp.escape(s)) # => /\\\\\\\*\\\?\\\{\\\}\\\./
1466
+ # r.match(s) # => #<MatchData "\\\\\\*\\?\\{\\}\\.">
1467
+ #
1468
+ alias self.quote self.escape
1469
+
1470
+ # <!--
1471
+ # rdoc-file=re.c
1472
+ # - Regexp.try_convert(object) -> regexp or nil
1473
+ # -->
1474
+ # Returns `object` if it is a regexp:
1475
+ #
1476
+ # Regexp.try_convert(/re/) # => /re/
1477
+ #
1478
+ # Otherwise if `object` responds to <code>:to_regexp</code>, calls
1479
+ # <code>object.to_regexp</code> and returns the result.
1480
+ #
1481
+ # Returns `nil` if `object` does not respond to <code>:to_regexp</code>.
1482
+ #
1483
+ # Regexp.try_convert('re') # => nil
1484
+ #
1485
+ # Raises an exception unless <code>object.to_regexp</code> returns a regexp.
1486
+ #
1487
+ def self.try_convert: (Regexp | _ToRegexp regexp_like) -> Regexp
1488
+ | (untyped other) -> Regexp?
1489
+
1490
+ # <!--
1491
+ # rdoc-file=re.c
1492
+ # - Regexp.timeout -> float or nil
1493
+ # -->
1494
+ # It returns the current default timeout interval for Regexp matching in second.
1495
+ # `nil` means no default timeout configuration.
1496
+ #
1497
+ def self.timeout: () -> Float?
1498
+
1499
+ # <!--
1500
+ # rdoc-file=re.c
1501
+ # - Regexp.timeout = float or nil
1502
+ # -->
1503
+ # It sets the default timeout interval for Regexp matching in second. `nil`
1504
+ # means no default timeout configuration. This configuration is process-global.
1505
+ # If you want to set timeout for each Regexp, use `timeout` keyword for
1506
+ # <code>Regexp.new</code>.
1507
+ #
1508
+ # Regexp.timeout = 1
1509
+ # /^a*b?a*$/ =~ "a" * 100000 + "x" #=> regexp match timeout (RuntimeError)
1510
+ #
1511
+ def self.timeout=: [T < _ToF] (T timeout) -> T
1512
+
1513
+ # <!--
1514
+ # rdoc-file=re.c
1515
+ # - Regexp.union(*patterns) -> regexp
1516
+ # - Regexp.union(array_of_patterns) -> regexp
1517
+ # -->
1518
+ # Returns a new regexp that is the union of the given patterns:
1519
+ #
1520
+ # r = Regexp.union(%w[cat dog]) # => /cat|dog/
1521
+ # r.match('cat') # => #<MatchData "cat">
1522
+ # r.match('dog') # => #<MatchData "dog">
1523
+ # r.match('cog') # => nil
1524
+ #
1525
+ # For each pattern that is a string, <code>Regexp.new(pattern)</code> is used:
1526
+ #
1527
+ # Regexp.union('penzance') # => /penzance/
1528
+ # Regexp.union('a+b*c') # => /a\+b\*c/
1529
+ # Regexp.union('skiing', 'sledding') # => /skiing|sledding/
1530
+ # Regexp.union(['skiing', 'sledding']) # => /skiing|sledding/
1531
+ #
1532
+ # For each pattern that is a regexp, it is used as is, including its flags:
1533
+ #
1534
+ # Regexp.union(/foo/i, /bar/m, /baz/x)
1535
+ # # => /(?i-mx:foo)|(?m-ix:bar)|(?x-mi:baz)/
1536
+ # Regexp.union([/foo/i, /bar/m, /baz/x])
1537
+ # # => /(?i-mx:foo)|(?m-ix:bar)|(?x-mi:baz)/
1538
+ #
1539
+ # With no arguments, returns <code>/(?!)/</code>:
1540
+ #
1541
+ # Regexp.union # => /(?!)/
1542
+ #
1543
+ # If any regexp pattern contains captures, the behavior is unspecified.
1544
+ #
1545
+ def self.union: (*Regexp | _ToRegexp | string patterns) -> Regexp
1546
+ | (array[Regexp | _ToRegexp | string] patterns) -> Regexp
1547
+ | (Symbol | [Symbol] symbol_pattern) -> Regexp
1548
+
1549
+ # <!--
1550
+ # rdoc-file=re.c
1551
+ # - Regexp.new(string, options = 0, timeout: nil) -> regexp
1552
+ # - Regexp.new(regexp, timeout: nil) -> regexp
1553
+ # -->
1554
+ # With argument `string` given, returns a new regexp with the given string and
1555
+ # options:
1556
+ #
1557
+ # r = Regexp.new('foo') # => /foo/
1558
+ # r.source # => "foo"
1559
+ # r.options # => 0
1560
+ #
1561
+ # Optional argument `options` is one of the following:
1562
+ #
1563
+ # * A String of options:
1564
+ #
1565
+ # Regexp.new('foo', 'i') # => /foo/i
1566
+ # Regexp.new('foo', 'im') # => /foo/im
1567
+ #
1568
+ # * The bit-wise OR of one or more of the constants Regexp::EXTENDED,
1569
+ # Regexp::IGNORECASE, Regexp::MULTILINE, and Regexp::NOENCODING:
1570
+ #
1571
+ # Regexp.new('foo', Regexp::IGNORECASE) # => /foo/i
1572
+ # Regexp.new('foo', Regexp::EXTENDED) # => /foo/x
1573
+ # Regexp.new('foo', Regexp::MULTILINE) # => /foo/m
1574
+ # Regexp.new('foo', Regexp::NOENCODING) # => /foo/n
1575
+ # flags = Regexp::IGNORECASE | Regexp::EXTENDED | Regexp::MULTILINE
1576
+ # Regexp.new('foo', flags) # => /foo/mix
1577
+ #
1578
+ # * `nil` or `false`, which is ignored.
1579
+ # * Any other truthy value, in which case the regexp will be case-insensitive.
1580
+ #
1581
+ # If optional keyword argument `timeout` is given, its float value overrides the
1582
+ # timeout interval for the class, Regexp.timeout. If `nil` is passed as
1583
+ # +timeout, it uses the timeout interval for the class, Regexp.timeout.
1584
+ #
1585
+ # With argument `regexp` given, returns a new regexp. The source, options,
1586
+ # timeout are the same as `regexp`. `options` and `n_flag` arguments are
1587
+ # ineffective. The timeout can be overridden by `timeout` keyword.
1588
+ #
1589
+ # options = Regexp::MULTILINE
1590
+ # r = Regexp.new('foo', options, timeout: 1.1) # => /foo/m
1591
+ # r2 = Regexp.new(r) # => /foo/m
1592
+ # r2.timeout # => 1.1
1593
+ # r3 = Regexp.new(r, timeout: 3.14) # => /foo/m
1594
+ # r3.timeout # => 3.14
1595
+ #
1596
+ def initialize: (Regexp regexp, ?timeout: _ToF?) -> void
1597
+ | (string pattern, ?int | string | bool | nil options, ?timeout: _ToF?) -> void
1598
+
1599
+ def initialize_copy: (self object) -> self
1600
+
1601
+ # <!-- rdoc-file=re.c -->
1602
+ # Returns `true` if `object` is another Regexp whose pattern, flags, and
1603
+ # encoding are the same as `self`, `false` otherwise:
1604
+ #
1605
+ # /foo/ == Regexp.new('foo') # => true
1606
+ # /foo/ == /foo/i # => false
1607
+ # /foo/ == Regexp.new('food') # => false
1608
+ # /foo/ == Regexp.new("abc".force_encoding("euc-jp")) # => false
1609
+ #
1610
+ def ==: (untyped other) -> bool
1611
+
1612
+ # <!--
1613
+ # rdoc-file=re.c
1614
+ # - regexp === string -> true or false
1615
+ # -->
1616
+ # Returns `true` if `self` finds a match in `string`:
1617
+ #
1618
+ # /^[a-z]*$/ === 'HELLO' # => false
1619
+ # /^[A-Z]*$/ === 'HELLO' # => true
1620
+ #
1621
+ # This method is called in case statements:
1622
+ #
1623
+ # s = 'HELLO'
1624
+ # case s
1625
+ # when /\A[a-z]*\z/; print "Lower case\n"
1626
+ # when /\A[A-Z]*\z/; print "Upper case\n"
1627
+ # else print "Mixed case\n"
1628
+ # end # => "Upper case"
1629
+ #
1630
+ def ===: (untyped other) -> bool
1631
+
1632
+ # <!--
1633
+ # rdoc-file=re.c
1634
+ # - regexp =~ string -> integer or nil
1635
+ # -->
1636
+ # Returns the integer index (in characters) of the first match for `self` and
1637
+ # `string`, or `nil` if none; also sets the [Regexp global
1638
+ # variables](rdoc-ref:Regexp@Global+Variables):
1639
+ #
1640
+ # /at/ =~ 'input data' # => 7
1641
+ # $~ # => #<MatchData "at">
1642
+ # /ax/ =~ 'input data' # => nil
1643
+ # $~ # => nil
1644
+ #
1645
+ # Assigns named captures to local variables of the same names if and only if
1646
+ # `self`:
1647
+ #
1648
+ # * Is a regexp literal; see [Regexp
1649
+ # Literals](rdoc-ref:syntax/literals.rdoc@Regexp+Literals).
1650
+ # * Does not contain interpolations; see [Regexp
1651
+ # interpolation](rdoc-ref:Regexp@Interpolation+Mode).
1652
+ # * Is at the left of the expression.
1653
+ #
1654
+ # Example:
1655
+ #
1656
+ # /(?<lhs>\w+)\s*=\s*(?<rhs>\w+)/ =~ ' x = y '
1657
+ # p lhs # => "x"
1658
+ # p rhs # => "y"
1659
+ #
1660
+ # Assigns `nil` if not matched:
1661
+ #
1662
+ # /(?<lhs>\w+)\s*=\s*(?<rhs>\w+)/ =~ ' x = '
1663
+ # p lhs # => nil
1664
+ # p rhs # => nil
1665
+ #
1666
+ # Does not make local variable assignments if `self` is not a regexp literal:
1667
+ #
1668
+ # r = /(?<foo>\w+)\s*=\s*(?<foo>\w+)/
1669
+ # r =~ ' x = y '
1670
+ # p foo # Undefined local variable
1671
+ # p bar # Undefined local variable
1672
+ #
1673
+ # The assignment does not occur if the regexp is not at the left:
1674
+ #
1675
+ # ' x = y ' =~ /(?<foo>\w+)\s*=\s*(?<foo>\w+)/
1676
+ # p foo, foo # Undefined local variables
1677
+ #
1678
+ # A regexp interpolation, <code>#{}</code>, also disables the assignment:
1679
+ #
1680
+ # r = /(?<foo>\w+)/
1681
+ # /(?<foo>\w+)\s*=\s*#{r}/ =~ 'x = y'
1682
+ # p foo # Undefined local variable
1683
+ #
1684
+ def =~: (interned? string) -> Integer?
1685
+ | (nil) -> nil
1686
+
1687
+ # <!--
1688
+ # rdoc-file=re.c
1689
+ # - casefold?-> true or false
1690
+ # -->
1691
+ # Returns `true` if the case-insensitivity flag in `self` is set, `false`
1692
+ # otherwise:
1693
+ #
1694
+ # /a/.casefold? # => false
1695
+ # /a/i.casefold? # => true
1696
+ # /(?i:a)/.casefold? # => false
1697
+ #
1698
+ def casefold?: () -> bool
1699
+
1700
+ # <!--
1701
+ # rdoc-file=re.c
1702
+ # - encoding -> encoding
1703
+ # -->
1704
+ # Returns an Encoding object that represents the encoding of `self`; see
1705
+ # [Encodings](rdoc-ref:encodings.rdoc).
1706
+ #
1707
+ # Related: see [Querying](rdoc-ref:String@Querying).
1708
+ #
1709
+ def encoding: () -> Encoding
1710
+
1711
+ # <!--
1712
+ # rdoc-file=re.c
1713
+ # - regexp == object -> true or false
1714
+ # -->
1715
+ # Returns `true` if `object` is another Regexp whose pattern, flags, and
1716
+ # encoding are the same as `self`, `false` otherwise:
1717
+ #
1718
+ # /foo/ == Regexp.new('foo') # => true
1719
+ # /foo/ == /foo/i # => false
1720
+ # /foo/ == Regexp.new('food') # => false
1721
+ # /foo/ == Regexp.new("abc".force_encoding("euc-jp")) # => false
1722
+ #
1723
+ alias eql? ==
1724
+
1725
+ # <!--
1726
+ # rdoc-file=re.c
1727
+ # - fixed_encoding? -> true or false
1728
+ # -->
1729
+ # Returns `false` if `self` is applicable to a string with any ASCII-compatible
1730
+ # encoding; otherwise returns `true`:
1731
+ #
1732
+ # r = /a/ # => /a/
1733
+ # r.fixed_encoding? # => false
1734
+ # r.match?("\u{6666} a") # => true
1735
+ # r.match?("\xa1\xa2 a".force_encoding("euc-jp")) # => true
1736
+ # r.match?("abc".force_encoding("euc-jp")) # => true
1737
+ #
1738
+ # r = /a/u # => /a/
1739
+ # r.fixed_encoding? # => true
1740
+ # r.match?("\u{6666} a") # => true
1741
+ # r.match?("\xa1\xa2".force_encoding("euc-jp")) # Raises exception.
1742
+ # r.match?("abc".force_encoding("euc-jp")) # => true
1743
+ #
1744
+ # r = /\u{6666}/ # => /\u{6666}/
1745
+ # r.fixed_encoding? # => true
1746
+ # r.encoding # => #<Encoding:UTF-8>
1747
+ # r.match?("\u{6666} a") # => true
1748
+ # r.match?("\xa1\xa2".force_encoding("euc-jp")) # Raises exception.
1749
+ # r.match?("abc".force_encoding("euc-jp")) # => false
1750
+ #
1751
+ def fixed_encoding?: () -> bool
1752
+
1753
+ # <!--
1754
+ # rdoc-file=re.c
1755
+ # - hash -> integer
1756
+ # -->
1757
+ # Returns the integer hash value for `self`.
1758
+ #
1759
+ # Related: Object#hash.
1760
+ #
1761
+ def hash: () -> Integer
1762
+
1763
+ # <!--
1764
+ # rdoc-file=re.c
1765
+ # - inspect -> string
1766
+ # -->
1767
+ # Returns a nicely-formatted string representation of `self`:
1768
+ #
1769
+ # /ab+c/ix.inspect # => "/ab+c/ix"
1770
+ #
1771
+ # Related: Regexp#to_s.
1772
+ #
1773
+ def inspect: () -> String
1774
+
1775
+ # <!--
1776
+ # rdoc-file=re.c
1777
+ # - match(string, offset = 0) -> matchdata or nil
1778
+ # - match(string, offset = 0) {|matchdata| ... } -> object
1779
+ # -->
1780
+ # With no block given, returns the MatchData object that describes the match, if
1781
+ # any, or `nil` if none; the search begins at the given character `offset` in
1782
+ # `string`:
1783
+ #
1784
+ # /abra/.match('abracadabra') # => #<MatchData "abra">
1785
+ # /abra/.match('abracadabra', 4) # => #<MatchData "abra">
1786
+ # /abra/.match('abracadabra', 8) # => nil
1787
+ # /abra/.match('abracadabra', 800) # => nil
1788
+ #
1789
+ # string = "\u{5d0 5d1 5e8 5d0}cadabra"
1790
+ # /abra/.match(string, 7) #=> #<MatchData "abra">
1791
+ # /abra/.match(string, 8) #=> nil
1792
+ # /abra/.match(string.b, 8) #=> #<MatchData "abra">
1793
+ #
1794
+ # With a block given, calls the block if and only if a match is found; returns
1795
+ # the block's value:
1796
+ #
1797
+ # /abra/.match('abracadabra') {|matchdata| p matchdata }
1798
+ # # => #<MatchData "abra">
1799
+ # /abra/.match('abracadabra', 4) {|matchdata| p matchdata }
1800
+ # # => #<MatchData "abra">
1801
+ # /abra/.match('abracadabra', 8) {|matchdata| p matchdata }
1802
+ # # => nil
1803
+ # /abra/.match('abracadabra', 8) {|marchdata| fail 'Cannot happen' }
1804
+ # # => nil
1805
+ #
1806
+ # Output (from the first two blocks above):
1807
+ #
1808
+ # #<MatchData "abra">
1809
+ # #<MatchData "abra">
1810
+ #
1811
+ # /(.)(.)(.)/.match("abc")[2] # => "b"
1812
+ # /(.)(.)/.match("abc", 1)[2] # => "c"
1813
+ #
1814
+ def match: (interned? str, ?int offset) -> MatchData?
1815
+ | [T] (interned? str, ?int offset) { (MatchData matchdata) -> T } -> T?
1816
+ | (nil, ?int offset) ?{ (MatchData matchdata) -> void } -> nil
1817
+
1818
+ # <!--
1819
+ # rdoc-file=re.c
1820
+ # - match?(string) -> true or false
1821
+ # - match?(string, offset = 0) -> true or false
1822
+ # -->
1823
+ # Returns `true` or `false` to indicate whether the regexp is matched or not
1824
+ # without updating $~ and other related variables. If the second parameter is
1825
+ # present, it specifies the position in the string to begin the search.
1826
+ #
1827
+ # /R.../.match?("Ruby") # => true
1828
+ # /R.../.match?("Ruby", 1) # => false
1829
+ # /P.../.match?("Ruby") # => false
1830
+ # $& # => nil
1831
+ #
1832
+ def match?: (interned str, ?int offset) -> bool
1833
+ | (nil, ?int offset) -> false
1834
+
1835
+ # <!--
1836
+ # rdoc-file=re.c
1837
+ # - named_captures -> hash
1838
+ # -->
1839
+ # Returns a hash representing named captures of `self` (see [Named
1840
+ # Captures](rdoc-ref:Regexp@Named+Captures)):
1841
+ #
1842
+ # * Each key is the name of a named capture.
1843
+ # * Each value is an array of integer indexes for that named capture.
1844
+ #
1845
+ # Examples:
1846
+ #
1847
+ # /(?<foo>.)(?<bar>.)/.named_captures # => {"foo"=>[1], "bar"=>[2]}
1848
+ # /(?<foo>.)(?<foo>.)/.named_captures # => {"foo"=>[1, 2]}
1849
+ # /(.)(.)/.named_captures # => {}
1850
+ #
1851
+ def named_captures: () -> Hash[String, Array[Integer]]
1852
+
1853
+ # <!--
1854
+ # rdoc-file=re.c
1855
+ # - names -> array_of_names
1856
+ # -->
1857
+ # Returns an array of names of captures (see [Named
1858
+ # Captures](rdoc-ref:Regexp@Named+Captures)):
1859
+ #
1860
+ # /(?<foo>.)(?<bar>.)(?<baz>.)/.names # => ["foo", "bar", "baz"]
1861
+ # /(?<foo>.)(?<foo>.)/.names # => ["foo"]
1862
+ # /(.)(.)/.names # => []
1863
+ #
1864
+ def names: () -> Array[String]
1865
+
1866
+ # <!--
1867
+ # rdoc-file=re.c
1868
+ # - options -> integer
1869
+ # -->
1870
+ # Returns an integer whose bits show the options set in `self`.
1871
+ #
1872
+ # The option bits are:
1873
+ #
1874
+ # Regexp::IGNORECASE # => 1
1875
+ # Regexp::EXTENDED # => 2
1876
+ # Regexp::MULTILINE # => 4
1877
+ #
1878
+ # Examples:
1879
+ #
1880
+ # /foo/.options # => 0
1881
+ # /foo/i.options # => 1
1882
+ # /foo/x.options # => 2
1883
+ # /foo/m.options # => 4
1884
+ # /foo/mix.options # => 7
1885
+ #
1886
+ # Note that additional bits may be set in the returned integer; these are
1887
+ # maintained internally in `self`, are ignored if passed to Regexp.new, and may
1888
+ # be ignored by the caller:
1889
+ #
1890
+ # Returns the set of bits corresponding to the options used when creating this
1891
+ # regexp (see Regexp::new for details). Note that additional bits may be set in
1892
+ # the returned options: these are used internally by the regular expression
1893
+ # code. These extra bits are ignored if the options are passed to Regexp::new:
1894
+ #
1895
+ # r = /\xa1\xa2/e # => /\xa1\xa2/
1896
+ # r.source # => "\\xa1\\xa2"
1897
+ # r.options # => 16
1898
+ # Regexp.new(r.source, r.options) # => /\xa1\xa2/
1899
+ #
1900
+ def options: () -> Integer
1901
+
1902
+ # <!--
1903
+ # rdoc-file=re.c
1904
+ # - source -> string
1905
+ # -->
1906
+ # Returns the original string of `self`:
1907
+ #
1908
+ # /ab+c/ix.source # => "ab+c"
1909
+ #
1910
+ # Regexp escape sequences are retained:
1911
+ #
1912
+ # /\x20\+/.source # => "\\x20\\+"
1913
+ #
1914
+ # Lexer escape characters are not retained:
1915
+ #
1916
+ # /\//.source # => "/"
1917
+ #
1918
+ def source: () -> String
1919
+
1920
+ # <!--
1921
+ # rdoc-file=re.c
1922
+ # - to_s -> string
1923
+ # -->
1924
+ # Returns a string showing the options and string of `self`:
1925
+ #
1926
+ # r0 = /ab+c/ix
1927
+ # s0 = r0.to_s # => "(?ix-m:ab+c)"
1928
+ #
1929
+ # The returned string may be used as an argument to Regexp.new, or as
1930
+ # interpolated text for a [Regexp
1931
+ # interpolation](rdoc-ref:Regexp@Interpolation+Mode):
1932
+ #
1933
+ # r1 = Regexp.new(s0) # => /(?ix-m:ab+c)/
1934
+ # r2 = /#{s0}/ # => /(?ix-m:ab+c)/
1935
+ #
1936
+ # Note that `r1` and `r2` are not equal to `r0` because their original strings
1937
+ # are different:
1938
+ #
1939
+ # r0 == r1 # => false
1940
+ # r0.source # => "ab+c"
1941
+ # r1.source # => "(?ix-m:ab+c)"
1942
+ #
1943
+ # Related: Regexp#inspect.
1944
+ #
1945
+ def to_s: () -> String
1946
+
1947
+ # <!--
1948
+ # rdoc-file=re.c
1949
+ # - rxp.timeout -> float or nil
1950
+ # -->
1951
+ # It returns the timeout interval for Regexp matching in second. `nil` means no
1952
+ # default timeout configuration.
1953
+ #
1954
+ # This configuration is per-object. The global configuration set by
1955
+ # Regexp.timeout= is ignored if per-object configuration is set.
1956
+ #
1957
+ # re = Regexp.new("^a*b?a*$", timeout: 1)
1958
+ # re.timeout #=> 1.0
1959
+ # re =~ "a" * 100000 + "x" #=> regexp match timeout (RuntimeError)
1960
+ #
1961
+ %a{pure}
1962
+ def timeout: () -> Float?
1963
+
1964
+ # <!--
1965
+ # rdoc-file=re.c
1966
+ # - ~ rxp -> integer or nil
1967
+ # -->
1968
+ # Equivalent to <code><i>rxp</i> =~ $_</code>:
1969
+ #
1970
+ # $_ = "input data"
1971
+ # ~ /at/ # => 7
1972
+ #
1973
+ def ~: () -> Integer?
1974
+ end