About Us
Products
Purchase
Downloads
Support
Forums
Contact Us
Site
 Register to post in forums, or Log in to your existing account
 

 Related 
Contents
Triggers
  #ACTION
  #ALARM
  #CONDITION
  #EVENT
  #FIRE
  #MXPTRIG
  #NOINPUT
  #ONINPUT
  #RAISEEVENT
  #SENDSB
  #SETPROMPT
  #TEMP
  #TRIGGER
  %alarm
  %state
  Create/Modify Settings
  Introduction to Triggers
  Multistate triggers
  Pattern Matching
  Trigger Tester
  Trigger Types
  Triggers
  Triggers
Command Reference
  #nnn
  #ABORT
  #ACTION
  #ADD
  #ADDITEM
  #ADDKEY
  #AFK
  #ALARM
  #ALIAS
  #ALL
  #BACKUP
  #BEEP
  #BREAK
  #BUTTON
  #C-
  #C+
  #CALL
  #CAPTURE
  #CASE
  #CHARACTER
  #CLASS
  #CLOSE
  #CLR
  #CMD
  #COLOR
  #COM
  #CONDITION
  #CONFIGURE
  #CONNECT
  #CONTINUE
  #CR
  #CW
  #DBCLOSE
  #DBDELETE
  #DBFIRST
  #DBGET
  #DBLOAD
  #DBNEXT
  #DBOFFLINE
  #DBONLINE
  #DBPREV
  #DBPUT
  #DBRESET
  #DBSAVE
  #DDE
  #DEBUG
  #DEBUGFILE
  #DEFAULT
  #DELCLASS
  #DELITEM
  #DELKEY
  #DELNITEM
  #DESCRIBE
  #DIRECTION
  #DISCONNECT
  #DOOR
  #ECHO
  #ECHOPROMPT
  #EDITOR
  #ERASE
  #EVALUATE
  #EVENT
  #EXECUTE
  #EXECWIN
  #EXIT
  #FILE
  #FIND
  #FIRE
  #FORALL
  #FREEZE
  #FTP
  #FUNCTION
  #GAG
  #GAGBLOCK
  #GAGLOG
  #GAGOFF
  #GAGON
  #GAGSPACE
  #GAUGE
  #H-
  #H+
  #HELP
  #HIGHLIGHT
  #HISTLOAD
  #HISTORY
  #HISTSAVE
  #HOST
  #IF
  #IGNORE
  #IMAGE
  #INPUT
  #KEY
  #KILLALL
  #LAUNCH
  #LMAP
  #LOAD
  #LOCAL
  #LOCATION
  #LOG
  #LOOK
  #LOOP
  #LOOPDB
  #LOOPVIEW
  #LUA
  #MAKEROOM
  #MAKEWINDOW
  #MAP
  #MAPQUERY
  #MARK
  #MATH
  #MEDIA
  #MENU
  #MERGE
  #MESSAGE
  #MODULE
  #MOVE
  #MSS
  #MXP
  #MXPTRIG
  #NAME
  #NEW
  #NEWVAR
  #NODEF
  #NODIR
  #NOINPUT
  #NOMAP
  #NOOP
  #NOSAVE
  #OK
  #ONINPUT
  #PATH
  #PATHHIGH
  #PAUSE
  #PCOL
  #PICK
  #PLAY
  #PLUGIN
  #PORTAL
  #PRINT
  #PROMPT
  #PSUB
  #PUEBLO
  #PW
  #QUERY
  #QUEUE
  #RAISEEVENT
  #READ
  #RECALL
  #RECORD
  #REGEX
  #RENAME
  #REPEAT
  #RESET
  #RESUME
  #RESULT
  #RETRACE
  #RETURN
  #SAVE
  #SAY
  #SAYADD
  #SAYPROMPT
  #SCRIPT
  #SCROLL
  #SECTION
  #SEND
  #SENDGMCP
  #SENDPROMPT
  #SENDRAW
  #SENDSB
  #SESSION
  #SET
  #SETPROMPT
  #SHOW
  #SHOWARR
  #SHOWDB
  #SHOWPROMPT
  #SHOWTABLE
  #SIGNAL
  #SLOW
  #SORT
  #SQLCLOSE
  #SQLDB
  #SS
  #STATE
  #STATUS
  #STEP
  #STOP
  #STWIN
  #STYLE
  #SUBSTITUTE
  #SUSPEND
  #SWITCH
  #T-
  #T?
  #T+
  #TAB
  #TAG
  #TELEPORT
  #TEMP
  #TEMPVAR
  #THREAD
  #TIMER
  #TRACK
  #TRIGGER
  #TSET
  #TYPE
  #TZERO
  #UNALIAS
  #UNBUTTON
  #UNCLASS
  #UNDIR
  #UNGAG
  #UNKEY
  #UNEVENT
  #UNLOAD
  #UNLOC
  #UNMENU
  #UNPATH
  #UNPORTAL
  #UNSTYLE
  #UNTAB
  #UNTIL
  #UNTRIGGER
  #UNVAR
  #UPDATE
  #URL
  #VARFUNC
  #VARIABLE
  #VERBATIM
  #VERSION
  #VIEW
  #WAIT
  #WAITFOR
  #WAITSIGNAL
  #WAITTHREAD
  #WALK
  #WHILE
  #WINDOW
  #WITHLOC
  #WIZLIST
  #WRAP
  #WRITE
  #WRITELOG
  #YESNO
Related Links:
  %regex
  %subregex
  Triggers
  Introduction to Triggers
  Pattern Matching
  Triggers
#REGEX [[cmud_#REG]] 
REGEX

Syntax: #REGEX id {pattern} {commands} classname options
Related: #TRIGGER, %regex

Creates a PERL Regular Expression trigger. The pattern field is the regular expression. It is expanded for @var variable references. The following regular expression patterns are supported:

. match any single character
* match zero or more of the previous pattern
+ match one or more of the previous pattern
? match zero or one of the previous pattern

(exp) group the regular expression "exp" into a single pattern. The matching pattern is stored in the %1..%99 variables.
(?:exp) group the regular expression as above, but do NOT store the value in the %1..%99 variables.

exp1 | exp2 match expression exp1 OR expression exp2. Any number of expressions can be listed, separated by |

[abc] match a range of letters. In this case, the letters a, b, or c are matched. You can specify a range of characters using the - operator. For example [a-z] matches any lowercase character. Putting ^ before the range defines a range of characters that are excluded. For example [^a-z] matches anything *except* a lowercase character.

^ matches the beginning of line
$ matches the end of the line

\ escapes the next character, matching that character verbatim. For example \* matches an asterisk. \ matches a slash itself. Note that to prevent CMUD variable parsing the @ character must still be escaped with the normal CMUD escape character (default of ~) rather than the \ character.

\s a space character (ascii 32)
\p the | pipe character
\w a word delimiter (matches a-zA-Z0-9)
\a a letter (matches a-zA-Z)
\d a digit (matches 0-9)
\h a hex character (0-9A-F)
\n matched a newline for multiline triggers

Like normal CMUD triggers, a subpattern can be enclosed in parenthesis to save it's matching pattern to the %1..%99 variables. To match a group of patterns without saving it to %nn, use the (?:exp) syntax. To save a subpattern to a named CMUD variable (like the &Varname syntax for normal triggers), use the (?Varname:exp) syntax.

Regular expression support is provided by the PCRE library package, which is open source software, written by Philip Hazel, and copyright
by the University of Cambridge, England. http://www.pcre.org/.

For additional help on Perl Regular Expressions, go to the Regular Expressions Information site on the Internet.

REGEX Example

#REGEX {a+} {#CW high,red}
Matches one or more 'a' characters and colors them red.

#REGEX {(Zugg|Darker)} {#CW high,red}
Matches any line that contains the word "Zugg" or the word "Darker" and colors the word in red.

 User comments 
Arminas: Thu Apr 17, 2008 7:28 pm    

Regex is implemented in case insensitive mode in CMUD so the example of [^a-z] actually says match anything but a letter instead of match anything but a lowercase letter.

Looking around for some solution I ran across this page. http://unicode.org/reports/tr18/

\p{Ll} is any lowercase letter Unicode
\p{Lu} is any uppercase letter Unicode

When case sensitivity came up on the forums JQuilici mentioned that you could turn off case insensitivity using "(?-i)" in your patterns

(?-i)[A-Z] Match only uppercase letters.
(?-i)[a-z] Match only lowercase letters.

Some other nice things to know.

\S is anything that is not a space or newline essentially [^\s]
\b A word boundary
\e the escape character this is equivalent to the %e in regular triggers.


When matching a list of things using Regex you can use (?:one|two|three|four).
This can be shortened if you have a variable that contains a string list by placing the variable into the pattern.
(?:@numbers)
Seb: Wed Jul 23, 2008 11:05 pm    

It is definitely worth noting on this manual page that the syntax listed is a subset of what is available. I was under the impression that what was listed here was what worked and other stuff didn't. Until I read another thread in the Beta forum about Vijilante's work on upgrading the PCRE library being used (etc.), and seeing some very complex regex patterns since then. (Maybe, until then, it was all the supported syntax though? Hmm, looking the PCRE news, I suspect this may be the case, or at least that there is a lot of new syntax available as a result of the update.) It is probably also worth noting which version of the PCRE is used, if an external reference is included instead of listing the available syntax, so that people can see which syntax is supported.

EDIT: Actually, for what's it's worth: I think 1 line on all supported REGEX would be helpful in the manual, since if a user is looking at the forums, trying to decipher some REGEX that someone wrote there, a quick reference is very helpful. Or even more so if they are offline, looking at a trigger in a package they didn't make.
Tech: Wed Jul 23, 2008 11:36 pm    

You may want to look at Advanced subregex in the documentation for more info.
Vijilante: Thu Jul 24, 2008 10:46 pm    

As of this moment, the version of the PCRE that is used in CMud is 7.6. PCRE stands for Perl Compatible Regular Expression, and supports everything in the Perl RegEx syntax. The PCRE 7.6 supports up to Perl 5.10.

There is also additional support for syntaxes that were originally devleoped by Python, Java, and the PCRE itself; however Perl has adopted a syntax for those specific items and the appropiate Perl documents can be used as a used a reference.

If anyone can find a link that is frequently updated with the latest Perl syntaxes please post it. All of my reference links only cover to about 4.2 of the Perl syntax, and I have yet to find a link that maintains an up to date version of the direct PCRE documentation.
mr_kent: Fri Jul 25, 2008 7:29 am    

Vijilante wrote:
If anyone can find a link that is frequently updated with the latest Perl syntaxes please post it. All of my reference links only cover to about 4.2 of the Perl syntax, and I have yet to find a link that maintains an up to date version of the direct PCRE documentation.


Is this what you're looking for?

Or possibly another link here or here?

Latest release is 7.7 according to the official PCRE website.

If this isn't what you wanted, please forgive my intrusion.

Found another link that looks like it is updated frequently but doesn't really say much.

Finally, the wiki.
haidivolume: Mon Jul 12, 2010 9:21 am    

Good read! Thanks!

Trains Toys & Hobbies, Mattel Barbie Toys
Viewer Comments [6 - Post your comments]

Jump to:  

© 2009 Zugg Software. Hosted by Wolfpaw.net