format_perl_syntax.qbk 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. [/
  2. Copyright 2006-2007 John Maddock.
  3. Distributed under the Boost Software License, Version 1.0.
  4. (See accompanying file LICENSE_1_0.txt or copy at
  5. http://www.boost.org/LICENSE_1_0.txt).
  6. ]
  7. [section:perl_format Perl Format String Syntax]
  8. Perl-style format strings treat all characters as literals except
  9. '$' and '\\' which start placeholder and escape sequences respectively.
  10. Placeholder sequences specify that some part of what matched the regular expression
  11. should be sent to output as follows:
  12. [table
  13. [[Placeholder][Meaning]]
  14. [[$&][Outputs what matched the whole expression.]]
  15. [[$MATCH][As $&]]
  16. [[${^MATCH}][As $&]]
  17. [[$\`][Outputs the text between the end of the last match found (or the
  18. start of the text if no previous match was found), and the start
  19. of the current match.]]
  20. [[$PREMATCH][As $\`]]
  21. [[${^PREMATCH}][As $\`]]
  22. [[$'][Outputs all the text following the end of the current match.]]
  23. [[$POSTMATCH][As $']]
  24. [[${^POSTMATCH}][As $']]
  25. [[$+][Outputs what matched the last marked sub-expression in the regular expression.]]
  26. [[$LAST_PAREN_MATCH][As $+]]
  27. [[$LAST_SUBMATCH_RESULT][Outputs what matched the last sub-expression to be actually matched.]]
  28. [[$^N][As $LAST_SUBMATCH_RESULT]]
  29. [[$$][Outputs a literal '$']]
  30. [[$n][Outputs what matched the n'th sub-expression.]]
  31. [[${n}][Outputs what matched the n'th sub-expression.]]
  32. [[$+{NAME}][Outputs whatever matched the sub-expression named "NAME".]]
  33. ]
  34. Any $-placeholder sequence not listed above, results in '$' being treated
  35. as a literal.
  36. An escape character followed by any character x, outputs that character unless
  37. x is one of the escape sequences shown below.
  38. [table
  39. [[Escape][Meaning]]
  40. [[\\a][Outputs the bell character: '\\a'.]]
  41. [[\\e][Outputs the ANSI escape character (code point 27).]]
  42. [[\\f][Outputs a form feed character: '\\f']]
  43. [[\\n][Outputs a newline character: '\\n'.]]
  44. [[\\r][Outputs a carriage return character: '\\r'.]]
  45. [[\\t][Outputs a tab character: '\\t'.]]
  46. [[\\v][Outputs a vertical tab character: '\\v'.]]
  47. [[\\xDD][Outputs the character whose hexadecimal code point is 0xDD]]
  48. [[\\x{DDDD}][Outputs the character whose hexadecimal code point is 0xDDDDD]]
  49. [[\\cX][Outputs the ANSI escape sequence "escape-X".]]
  50. [[\\D][If D is a decimal digit in the range 1-9, then outputs the text that matched sub-expression D.]]
  51. [[\\l][Causes the next character to be outputted, to be output in lower case.]]
  52. [[\\u][Causes the next character to be outputted, to be output in upper case.]]
  53. [[\\L][Causes all subsequent characters to be output in lower case, until a \\E is found.]]
  54. [[\\U][Causes all subsequent characters to be output in upper case, until a \\E is found.]]
  55. [[\\E][Terminates a \\L or \\U sequence.]]
  56. ]
  57. [endsect]