[Home] [Downloads] [Search] [Help/forum]

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  regexp: match multiple consecutive whole words on the same line
Home  |  Users  |  Search  |  FAQ
Register forum user name
Forgotten password?

regexp: match multiple consecutive whole words on the same line

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Posted by Missingl   (2 posts)  [Biography] bio
Date Sat 15 Jul 2006 02:44 PM (UTC)
Hi all,

i'd like to write some regular expressions which match whole (specified) words on a line. For example, the string:

You feel weaker as the power of the Strength spell wanes.

i wish to filter (mark / change colour of) all instances of:

now if i use " (you|as|the|of|one|on) ", (with keep evaluating and repeat on same line ticked) if two matching words occur next to each other, it only matches the first. if another word matches further down the string, however, it matches ok.

the reason for the spaces on either side of the regexp is so it matches the entire word. i don't want it to match, for example, the "the" in "these", and therefore mark half the word.

of course one could capture all the words in the line, and parse it via script, and cause the output to popup else where, but i think speedwise the trigger only would be a tad quicker.

finally, awesome client, best i've come across yet, excellent work Nick.

thanks for any help.

[Go to top] top

Posted by Shadowfyr   USA  (1,783 posts)  [Biography] bio
Date Reply #1 on Sat 15 Jul 2006 07:18 PM (UTC)

Amended on Sat 15 Jul 2006 07:19 PM (UTC) by Shadowfyr

Umm.. Well, the reason for this is simple. You're telling it to do this:

string = " on on one "
Search 1 = " on on one "
            ^  ^
Search 2 = "on one "
              ^   ^

Where ^ is where it finds the start and end of the next "match".

In other words, since you are specifically looking for the space, its incrementing the point where it starts looking again "past" that space. This should fix it (uses no spaces):


The explaination given in Mushclient's documentation is from one of those horrible, "If you are reading this, you should understand what I mean.", documents you often get in the world of "professionals", who all speak Computer Nerd. Apparently I need to take a course on it, since I can't comprehend half the more obscure stuff in the Regexp documents. lol

Just to make sure I was understanding it though, I googled for a better explaination:


"\b" is basically an assertion that the following match "must" have one character on either side be a \w (letter), while the other "must" be a \W (spaces, newline, etc.). It does not include the characters it finds in what it returns, so it should only match the word itself, meaning that the next search will start with the space following the word it found.
[Go to top] top

Posted by Nick Gammon   Australia  (21,675 posts)  [Biography] bio   Forum Administrator
Date Reply #2 on Sat 15 Jul 2006 09:50 PM (UTC)
My forum post about regular expressions explains in quite a bit of detail:


Shadowfyr is right, you want an "assertion" (which does not actually consume characters) rather than a match.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Missingl   (2 posts)  [Biography] bio
Date Reply #3 on Sun 16 Jul 2006 02:21 PM (UTC)
thanks guys,

that was a little too easy for you, i'm kinda embarrassed. Nonetheless, what you suggested worked perfectly shadowfyr, thank you.

Also thanks for the link Nick, looking through the forums i missed it. i'll be sure to have a look at it thoroughly.


[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum

[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]