brazilofmux / tinymux

TinyMUX
www.tinymux.org
48 stars 21 forks source link

The borrowing of regedit() and friends #347

Open brazilofmux opened 9 years ago

brazilofmux commented 9 years ago

Original issue 344 created by brazilofmux on 2007-06-27T18:31:47.000Z:

TinyMUX currently does not have the regedit() family of functions; some would suggest it should.

From Penn's help regedit():

help regedit REGEDIT() regedit(<string>, <regexp>, <replacement>[, ... , <regexpN>, <replaceN>]) regediti(<string>, <regexp>, <replacement>[, ... , <regexpN>, <replaceN>]) regeditall(<string>, <regexp>, <replacement>[, ... , <regexpN>, <replaceN>]) regeditalli(<string>, <regexp>, <replacement>[, ... , <regexpN>, <replaceN>])

These functions are a version of edit() that uses regular expressions. The part of <string> that matches the <regexp> is replaced by the evaluated <replacement>, with $<number> in <replacement> expanded to the corresponding matching sub-expression of <regexp>, with $0 the entire matched section. If you use named sub-expressions (?P<foo>subexpr), they are referred with with $<foo> (Note that the <>'s are literal).

regedit() only replaces the first match. regeditall() replaces all matches. The versions ending in i are case insensitive. The <replacement> argument is evaluated once for each match, allowing for more complex transformations than is possible with straight replacement.

Examples: > say regedit(this test is the best string, (?P<char>.)est, $<char>rash) You say "this trash is the best string" > say regeditall(this test is the best string, (.)est, [capstr($1)]rash) You say "this Trash is the Brash string"

See also: edit(), regmatch()

brazilofmux commented 9 years ago

Comment #1 originally posted by brazilofmux on 2007-09-21T00:13:50.000Z:

Maybe, we'll find time for this towards the end of 2.7, but for now, I'm moving it to 2.8.