home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 5 / DATAFILE_PDCD5.iso / utilities / p / python / pytexdoc / ext / lib / lib1 / regsub / tex
LaTeX Document  |  1996-11-08  |  2.2 KB

open in: MacOS 8.1     |     Win98     |     DOS

view JSON data     |     view as text

This file was processed as: LaTeX Document (document/latex).

You can browse this item here: tex

ConfidenceProgramDetectionMatch TypeSupport
100% dexvert LaTeX Document (document/latex) magic Supported
1% dexvert Text File (text/txt) fallback Supported
100% file LaTeX document text default
99% file LaTeX document, ASCII text default
100% checkBytes Printable ASCII default
100% perlTextCheck Likely Text (Perl) default
100% siegfried fmt/281 LaTeX (Subdocument) default
100% detectItEasy Format: plain text[LF] default (weak)



hex view
+--------+-------------------------+-------------------------+--------+--------+
|00000000| 5c 73 65 63 74 69 6f 6e | 7b 53 74 61 6e 64 61 72 |\section|{Standar|
|00000010| 64 20 4d 6f 64 75 6c 65 | 20 5c 73 65 63 74 63 6f |d Module| \sectco|
|00000020| 64 65 7b 72 65 67 73 75 | 62 7d 7d 0a 0a 5c 73 74 |de{regsu|b}}..\st|
|00000030| 6d 6f 64 69 6e 64 65 78 | 7b 72 65 67 73 75 62 7d |modindex|{regsub}|
|00000040| 0a 54 68 69 73 20 6d 6f | 64 75 6c 65 20 64 65 66 |.This mo|dule def|
|00000050| 69 6e 65 73 20 61 20 6e | 75 6d 62 65 72 20 6f 66 |ines a n|umber of|
|00000060| 20 66 75 6e 63 74 69 6f | 6e 73 20 75 73 65 66 75 | functio|ns usefu|
|00000070| 6c 20 66 6f 72 20 77 6f | 72 6b 69 6e 67 20 77 69 |l for wo|rking wi|
|00000080| 74 68 0a 72 65 67 75 6c | 61 72 20 65 78 70 72 65 |th.regul|ar expre|
|00000090| 73 73 69 6f 6e 73 20 28 | 73 65 65 20 62 75 69 6c |ssions (|see buil|
|000000a0| 74 2d 69 6e 20 6d 6f 64 | 75 6c 65 20 5c 63 6f 64 |t-in mod|ule \cod|
|000000b0| 65 7b 72 65 67 65 78 7d | 29 2e 0a 0a 57 61 72 6e |e{regex}|)...Warn|
|000000c0| 69 6e 67 3a 20 74 68 65 | 73 65 20 66 75 6e 63 74 |ing: the|se funct|
|000000d0| 69 6f 6e 73 20 61 72 65 | 20 6e 6f 74 20 74 68 72 |ions are| not thr|
|000000e0| 65 61 64 2d 73 61 66 65 | 2e 0a 0a 5c 72 65 6e 65 |ead-safe|...\rene|
|000000f0| 77 63 6f 6d 6d 61 6e 64 | 7b 5c 69 6e 64 65 78 73 |wcommand|{\indexs|
|00000100| 75 62 69 74 65 6d 7d 7b | 28 69 6e 20 6d 6f 64 75 |ubitem}{|(in modu|
|00000110| 6c 65 20 72 65 67 73 75 | 62 29 7d 0a 0a 5c 62 65 |le regsu|b)}..\be|
|00000120| 67 69 6e 7b 66 75 6e 63 | 64 65 73 63 7d 7b 73 75 |gin{func|desc}{su|
|00000130| 62 7d 7b 70 61 74 5c 2c | 20 72 65 70 6c 5c 2c 20 |b}{pat\,| repl\, |
|00000140| 73 74 72 7d 0a 52 65 70 | 6c 61 63 65 20 74 68 65 |str}.Rep|lace the|
|00000150| 20 66 69 72 73 74 20 6f | 63 63 75 72 72 65 6e 63 | first o|ccurrenc|
|00000160| 65 20 6f 66 20 70 61 74 | 74 65 72 6e 20 5c 76 61 |e of pat|tern \va|
|00000170| 72 7b 70 61 74 7d 20 69 | 6e 20 73 74 72 69 6e 67 |r{pat} i|n string|
|00000180| 0a 5c 76 61 72 7b 73 74 | 72 7d 20 62 79 20 72 65 |.\var{st|r} by re|
|00000190| 70 6c 61 63 65 6d 65 6e | 74 20 5c 76 61 72 7b 72 |placemen|t \var{r|
|000001a0| 65 70 6c 7d 2e 20 20 49 | 66 20 74 68 65 20 70 61 |epl}. I|f the pa|
|000001b0| 74 74 65 72 6e 20 69 73 | 6e 27 74 20 66 6f 75 6e |ttern is|n't foun|
|000001c0| 64 2c 0a 74 68 65 20 73 | 74 72 69 6e 67 20 69 73 |d,.the s|tring is|
|000001d0| 20 72 65 74 75 72 6e 65 | 64 20 75 6e 63 68 61 6e | returne|d unchan|
|000001e0| 67 65 64 2e 20 20 54 68 | 65 20 70 61 74 74 65 72 |ged. Th|e patter|
|000001f0| 6e 20 6d 61 79 20 62 65 | 20 61 20 73 74 72 69 6e |n may be| a strin|
|00000200| 67 20 6f 72 20 61 6e 0a | 61 6c 72 65 61 64 79 20 |g or an.|already |
|00000210| 63 6f 6d 70 69 6c 65 64 | 20 70 61 74 74 65 72 6e |compiled| pattern|
|00000220| 2e 20 20 54 68 65 20 72 | 65 70 6c 61 63 65 6d 65 |. The r|eplaceme|
|00000230| 6e 74 20 6d 61 79 20 63 | 6f 6e 74 61 69 6e 20 72 |nt may c|ontain r|
|00000240| 65 66 65 72 65 6e 63 65 | 73 0a 5c 73 61 6d 70 7b |eference|s.\samp{|
|00000250| 5c 65 20 5c 76 61 72 7b | 64 69 67 69 74 7d 7d 20 |\e \var{|digit}} |
|00000260| 74 6f 20 73 75 62 70 61 | 74 74 65 72 6e 73 20 61 |to subpa|tterns a|
|00000270| 6e 64 20 65 73 63 61 70 | 65 64 20 62 61 63 6b 73 |nd escap|ed backs|
|00000280| 6c 61 73 68 65 73 2e 0a | 5c 65 6e 64 7b 66 75 6e |lashes..|\end{fun|
|00000290| 63 64 65 73 63 7d 0a 0a | 5c 62 65 67 69 6e 7b 66 |cdesc}..|\begin{f|
|000002a0| 75 6e 63 64 65 73 63 7d | 7b 67 73 75 62 7d 7b 70 |uncdesc}|{gsub}{p|
|000002b0| 61 74 5c 2c 20 72 65 70 | 6c 5c 2c 20 73 74 72 7d |at\, rep|l\, str}|
|000002c0| 0a 52 65 70 6c 61 63 65 | 20 61 6c 6c 20 28 6e 6f |.Replace| all (no|
|000002d0| 6e 2d 6f 76 65 72 6c 61 | 70 70 69 6e 67 29 20 6f |n-overla|pping) o|
|000002e0| 63 63 75 72 72 65 6e 63 | 65 73 20 6f 66 20 70 61 |ccurrenc|es of pa|
|000002f0| 74 74 65 72 6e 20 5c 76 | 61 72 7b 70 61 74 7d 20 |ttern \v|ar{pat} |
|00000300| 69 6e 0a 73 74 72 69 6e | 67 20 5c 76 61 72 7b 73 |in.strin|g \var{s|
|00000310| 74 72 7d 20 62 79 20 72 | 65 70 6c 61 63 65 6d 65 |tr} by r|eplaceme|
|00000320| 6e 74 20 5c 76 61 72 7b | 72 65 70 6c 7d 2e 20 20 |nt \var{|repl}. |
|00000330| 54 68 65 20 73 61 6d 65 | 20 72 75 6c 65 73 20 61 |The same| rules a|
|00000340| 73 20 66 6f 72 0a 5c 63 | 6f 64 65 7b 73 75 62 28 |s for.\c|ode{sub(|
|00000350| 29 7d 20 61 70 70 6c 79 | 2e 20 20 45 6d 70 74 79 |)} apply|. Empty|
|00000360| 20 6d 61 74 63 68 65 73 | 20 66 6f 72 20 74 68 65 | matches| for the|
|00000370| 20 70 61 74 74 65 72 6e | 20 61 72 65 20 72 65 70 | pattern| are rep|
|00000380| 6c 61 63 65 64 20 6f 6e | 6c 79 0a 77 68 65 6e 20 |laced on|ly.when |
|00000390| 6e 6f 74 20 61 64 6a 61 | 63 65 6e 74 20 74 6f 20 |not adja|cent to |
|000003a0| 61 20 70 72 65 76 69 6f | 75 73 20 6d 61 74 63 68 |a previo|us match|
|000003b0| 2c 20 73 6f 20 65 2e 67 | 2e 0a 5c 63 6f 64 65 7b |, so e.g|..\code{|
|000003c0| 67 73 75 62 28 27 27 2c | 20 27 2d 27 2c 20 27 61 |gsub('',| '-', 'a|
|000003d0| 62 63 27 29 7d 20 72 65 | 74 75 72 6e 73 20 5c 63 |bc')} re|turns \c|
|000003e0| 6f 64 65 7b 27 2d 61 2d | 62 2d 63 2d 27 7d 2e 0a |ode{'-a-|b-c-'}..|
|000003f0| 5c 65 6e 64 7b 66 75 6e | 63 64 65 73 63 7d 0a 0a |\end{fun|cdesc}..|
|00000400| 5c 62 65 67 69 6e 7b 66 | 75 6e 63 64 65 73 63 7d |\begin{f|uncdesc}|
|00000410| 7b 73 70 6c 69 74 7d 7b | 73 74 72 5c 2c 20 70 61 |{split}{|str\, pa|
|00000420| 74 5c 6f 70 74 69 6f 6e | 61 6c 7b 5c 2c 20 6d 61 |t\option|al{\, ma|
|00000430| 78 73 70 6c 69 74 7d 7d | 0a 53 70 6c 69 74 20 74 |xsplit}}|.Split t|
|00000440| 68 65 20 73 74 72 69 6e | 67 20 5c 76 61 72 7b 73 |he strin|g \var{s|
|00000450| 74 72 7d 20 69 6e 20 66 | 69 65 6c 64 73 20 73 65 |tr} in f|ields se|
|00000460| 70 61 72 61 74 65 64 20 | 62 79 20 64 65 6c 69 6d |parated |by delim|
|00000470| 69 74 65 72 73 20 6d 61 | 74 63 68 69 6e 67 0a 74 |iters ma|tching.t|
|00000480| 68 65 20 70 61 74 74 65 | 72 6e 20 5c 76 61 72 7b |he patte|rn \var{|
|00000490| 70 61 74 7d 2c 20 61 6e | 64 20 72 65 74 75 72 6e |pat}, an|d return|
|000004a0| 20 61 20 6c 69 73 74 20 | 63 6f 6e 74 61 69 6e 69 | a list |containi|
|000004b0| 6e 67 20 74 68 65 20 66 | 69 65 6c 64 73 2e 20 20 |ng the f|ields. |
|000004c0| 4f 6e 6c 79 0a 6e 6f 6e | 2d 65 6d 70 74 79 20 6d |Only.non|-empty m|
|000004d0| 61 74 63 68 65 73 20 66 | 6f 72 20 74 68 65 20 70 |atches f|or the p|
|000004e0| 61 74 74 65 72 6e 20 61 | 72 65 20 63 6f 6e 73 69 |attern a|re consi|
|000004f0| 64 65 72 65 64 2c 20 73 | 6f 20 65 2e 67 2e 0a 5c |dered, s|o e.g..\|
|00000500| 63 6f 64 65 7b 73 70 6c | 69 74 28 27 61 3a 62 27 |code{spl|it('a:b'|
|00000510| 2c 20 27 3a 2a 27 29 7d | 20 72 65 74 75 72 6e 73 |, ':*')}| returns|
|00000520| 20 5c 63 6f 64 65 7b 5b | 27 61 27 2c 20 27 62 27 | \code{[|'a', 'b'|
|00000530| 5d 7d 20 61 6e 64 0a 5c | 63 6f 64 65 7b 73 70 6c |]} and.\|code{spl|
|00000540| 69 74 28 27 61 62 63 27 | 2c 20 27 27 29 7d 20 72 |it('abc'|, '')} r|
|00000550| 65 74 75 72 6e 73 20 5c | 63 6f 64 65 7b 5b 27 61 |eturns \|code{['a|
|00000560| 62 63 27 5d 7d 2e 20 20 | 54 68 65 20 5c 76 61 72 |bc']}. |The \var|
|00000570| 7b 6d 61 78 73 70 6c 69 | 74 7d 0a 64 65 66 61 75 |{maxspli|t}.defau|
|00000580| 6c 74 73 20 74 6f 20 30 | 2e 20 49 66 20 69 74 20 |lts to 0|. If it |
|00000590| 69 73 20 6e 6f 6e 7a 65 | 72 6f 2c 20 6f 6e 6c 79 |is nonze|ro, only|
|000005a0| 20 5c 76 61 72 7b 6d 61 | 78 73 70 6c 69 74 7d 20 | \var{ma|xsplit} |
|000005b0| 6e 75 6d 62 65 72 20 6f | 66 20 73 70 6c 69 74 73 |number o|f splits|
|000005c0| 0a 6f 63 63 75 72 2c 20 | 61 6e 64 20 74 68 65 20 |.occur, |and the |
|000005d0| 72 65 6d 61 69 6e 64 65 | 72 20 6f 66 20 74 68 65 |remainde|r of the|
|000005e0| 20 73 74 72 69 6e 67 20 | 69 73 20 72 65 74 75 72 | string |is retur|
|000005f0| 6e 65 64 20 61 73 20 74 | 68 65 20 66 69 6e 61 6c |ned as t|he final|
|00000600| 0a 65 6c 65 6d 65 6e 74 | 20 6f 66 20 74 68 65 20 |.element| of the |
|00000610| 6c 69 73 74 2e 0a 5c 65 | 6e 64 7b 66 75 6e 63 64 |list..\e|nd{funcd|
|00000620| 65 73 63 7d 0a 0a 5c 62 | 65 67 69 6e 7b 66 75 6e |esc}..\b|egin{fun|
|00000630| 63 64 65 73 63 7d 7b 73 | 70 6c 69 74 78 7d 7b 73 |cdesc}{s|plitx}{s|
|00000640| 74 72 5c 2c 20 70 61 74 | 5c 6f 70 74 69 6f 6e 61 |tr\, pat|\optiona|
|00000650| 6c 7b 5c 2c 20 6d 61 78 | 73 70 6c 69 74 7d 7d 0a |l{\, max|split}}.|
|00000660| 53 70 6c 69 74 20 74 68 | 65 20 73 74 72 69 6e 67 |Split th|e string|
|00000670| 20 5c 76 61 72 7b 73 74 | 72 7d 20 69 6e 20 66 69 | \var{st|r} in fi|
|00000680| 65 6c 64 73 20 73 65 70 | 61 72 61 74 65 64 20 62 |elds sep|arated b|
|00000690| 79 20 64 65 6c 69 6d 69 | 74 65 72 73 20 6d 61 74 |y delimi|ters mat|
|000006a0| 63 68 69 6e 67 0a 74 68 | 65 20 70 61 74 74 65 72 |ching.th|e patter|
|000006b0| 6e 20 5c 76 61 72 7b 70 | 61 74 7d 2c 20 61 6e 64 |n \var{p|at}, and|
|000006c0| 20 72 65 74 75 72 6e 20 | 61 20 6c 69 73 74 20 63 | return |a list c|
|000006d0| 6f 6e 74 61 69 6e 69 6e | 67 20 74 68 65 20 66 69 |ontainin|g the fi|
|000006e0| 65 6c 64 73 20 61 73 20 | 77 65 6c 6c 0a 61 73 20 |elds as |well.as |
|000006f0| 74 68 65 20 73 65 70 61 | 72 61 74 6f 72 73 2e 20 |the sepa|rators. |
|00000700| 20 46 6f 72 20 65 78 61 | 6d 70 6c 65 2c 20 5c 63 | For exa|mple, \c|
|00000710| 6f 64 65 7b 73 70 6c 69 | 74 78 28 27 61 3a 3a 3a |ode{spli|tx('a:::|
|00000720| 62 27 2c 20 27 3a 2a 27 | 29 7d 20 72 65 74 75 72 |b', ':*'|)} retur|
|00000730| 6e 73 0a 5c 63 6f 64 65 | 7b 5b 27 61 27 2c 20 27 |ns.\code|{['a', '|
|00000740| 3a 3a 3a 27 2c 20 27 62 | 27 5d 7d 2e 20 20 4f 74 |:::', 'b|']}. Ot|
|00000750| 68 65 72 77 69 73 65 2c | 20 74 68 69 73 20 66 75 |herwise,| this fu|
|00000760| 6e 63 74 69 6f 6e 20 62 | 65 68 61 76 65 73 20 74 |nction b|ehaves t|
|00000770| 68 65 20 73 61 6d 65 0a | 61 73 20 5c 63 6f 64 65 |he same.|as \code|
|00000780| 7b 73 70 6c 69 74 7d 2e | 0a 5c 65 6e 64 7b 66 75 |{split}.|.\end{fu|
|00000790| 6e 63 64 65 73 63 7d 0a | 0a 5c 62 65 67 69 6e 7b |ncdesc}.|.\begin{|
|000007a0| 66 75 6e 63 64 65 73 63 | 7d 7b 63 61 70 77 6f 72 |funcdesc|}{capwor|
|000007b0| 64 73 7d 7b 73 5c 6f 70 | 74 69 6f 6e 61 6c 7b 5c |ds}{s\op|tional{\|
|000007c0| 2c 20 70 61 74 7d 7d 0a | 43 61 70 69 74 61 6c 69 |, pat}}.|Capitali|
|000007d0| 7a 65 20 77 6f 72 64 73 | 20 73 65 70 61 72 61 74 |ze words| separat|
|000007e0| 65 64 20 62 79 20 6f 70 | 74 69 6f 6e 61 6c 20 70 |ed by op|tional p|
|000007f0| 61 74 74 65 72 6e 20 5c | 76 61 72 7b 70 61 74 7d |attern \|var{pat}|
|00000800| 2e 20 20 54 68 65 20 64 | 65 66 61 75 6c 74 0a 70 |. The d|efault.p|
|00000810| 61 74 74 65 72 6e 20 75 | 73 65 73 20 61 6e 79 20 |attern u|ses any |
|00000820| 63 68 61 72 61 63 74 65 | 72 73 20 65 78 63 65 70 |characte|rs excep|
|00000830| 74 20 6c 65 74 74 65 72 | 73 2c 20 64 69 67 69 74 |t letter|s, digit|
|00000840| 73 20 61 6e 64 20 75 6e | 64 65 72 73 63 6f 72 65 |s and un|derscore|
|00000850| 73 20 61 73 0a 77 6f 72 | 64 20 64 65 6c 69 6d 69 |s as.wor|d delimi|
|00000860| 74 65 72 73 2e 20 20 43 | 61 70 69 74 61 6c 69 7a |ters. C|apitaliz|
|00000870| 61 74 69 6f 6e 20 69 73 | 20 64 6f 6e 65 20 62 79 |ation is| done by|
|00000880| 20 63 68 61 6e 67 69 6e | 67 20 74 68 65 20 66 69 | changin|g the fi|
|00000890| 72 73 74 0a 63 68 61 72 | 61 63 74 65 72 20 6f 66 |rst.char|acter of|
|000008a0| 20 65 61 63 68 20 77 6f | 72 64 20 74 6f 20 75 70 | each wo|rd to up|
|000008b0| 70 65 72 20 63 61 73 65 | 2e 0a 5c 65 6e 64 7b 66 |per case|..\end{f|
|000008c0| 75 6e 63 64 65 73 63 7d | 0a |uncdesc}|. |
+--------+-------------------------+-------------------------+--------+--------+