re.d.elv 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #elvdoc:fn quote
  2. #
  3. # ```elvish
  4. # re:quote $string
  5. # ```
  6. #
  7. # Quote `$string` for use in a pattern. Examples:
  8. #
  9. # ```elvish-transcript
  10. # ~> re:quote a.txt
  11. # ▶ a\.txt
  12. # ~> re:quote '(*)'
  13. # ▶ '\(\*\)'
  14. # ```
  15. #elvdoc:fn match
  16. #
  17. # ```elvish
  18. # re:match &posix=$false $pattern $source
  19. # ```
  20. #
  21. # Determine whether `$pattern` matches `$source`. The pattern is not anchored.
  22. # Examples:
  23. #
  24. # ```elvish-transcript
  25. # ~> re:match . xyz
  26. # ▶ $true
  27. # ~> re:match . ''
  28. # ▶ $false
  29. # ~> re:match '[a-z]' A
  30. # ▶ $false
  31. # ```
  32. #elvdoc:fn find
  33. #
  34. # ```elvish
  35. # re:find &posix=$false &longest=$false &max=-1 $pattern $source
  36. # ```
  37. #
  38. # Find all matches of `$pattern` in `$source`.
  39. #
  40. # Each match is represented by a map-like value `$m`; `$m[text]`, `$m[start]` and
  41. # `$m[end]` are the text, start and end positions (as byte indices into `$source`)
  42. # of the match; `$m[groups]` is a list of submatches for capture groups in the
  43. # pattern. A submatch has a similar structure to a match, except that it does not
  44. # have a `group` key. The entire pattern is an implicit capture group, and it
  45. # always appears first.
  46. #
  47. # Examples:
  48. #
  49. # ```elvish-transcript
  50. # ~> re:find . ab
  51. # ▶ [&text=a &start=0 &end=1 &groups=[[&text=a &start=0 &end=1]]]
  52. # ▶ [&text=b &start=1 &end=2 &groups=[[&text=b &start=1 &end=2]]]
  53. # ~> re:find '[A-Z]([0-9])' 'A1 B2'
  54. # ▶ [&text=A1 &start=0 &end=2 &groups=[[&text=A1 &start=0 &end=2] [&text=1 &start=1 &end=2]]]
  55. # ▶ [&text=B2 &start=3 &end=5 &groups=[[&text=B2 &start=3 &end=5] [&text=2 &start=4 &end=5]]]
  56. # ```
  57. #elvdoc:fn replace
  58. #
  59. # ```elvish
  60. # re:replace &posix=$false &longest=$false &literal=$false $pattern $repl $source
  61. # ```
  62. #
  63. # Replace all occurrences of `$pattern` in `$source` with `$repl`.
  64. #
  65. # The replacement `$repl` can be any of the following:
  66. #
  67. # - A string-typed replacement template. The template can use `$name` or
  68. # `${name}` patterns to refer to capture groups, where `name` consists of
  69. # letters, digits and underscores. A purely numeric patterns like `$1`
  70. # refers to the capture group with the corresponding index; other names
  71. # refer to capture groups named with the `(?P<name>...)`) syntax.
  72. #
  73. # In the `$name` form, the name is taken to be as long as possible; `$1` is
  74. # equivalent to `${1x}`, not `${1}x`; `$10` is equivalent to `${10}`, not `${1}0`.
  75. #
  76. # To insert a literal `$`, use `$$`.
  77. #
  78. # - A function that takes a string argument and outputs a string. For each
  79. # match, the function is called with the content of the match, and its output
  80. # is used as the replacement.
  81. #
  82. # If `$literal` is true, `$repl` must be a string and is treated literally instead
  83. # of as a pattern.
  84. #
  85. # Example:
  86. #
  87. # ```elvish-transcript
  88. # ~> re:replace '(ba|z)sh' '${1}SH' 'bash and zsh'
  89. # ▶ 'baSH and zSH'
  90. # ~> re:replace '(ba|z)sh' elvish 'bash and zsh rock'
  91. # ▶ 'elvish and elvish rock'
  92. # ~> re:replace '(ba|z)sh' {|x| put [&bash=BaSh &zsh=ZsH][$x] } 'bash and zsh'
  93. # ▶ 'BaSh and ZsH'
  94. # ```
  95. #elvdoc:fn split
  96. #
  97. # ```elvish
  98. # re:split &posix=$false &longest=$false &max=-1 $pattern $source
  99. # ```
  100. #
  101. # Split `$source`, using `$pattern` as separators. Examples:
  102. #
  103. # ```elvish-transcript
  104. # ~> re:split : /usr/sbin:/usr/bin:/bin
  105. # ▶ /usr/sbin
  106. # ▶ /usr/bin
  107. # ▶ /bin
  108. # ~> re:split &max=2 : /usr/sbin:/usr/bin:/bin
  109. # ▶ /usr/sbin
  110. # ▶ /usr/bin:/bin
  111. # ```