Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ General ➜ reg expression matching

reg expression matching

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


Posted by Neverwhere   USA  (40 posts)  Bio
Date Thu 10 Jul 2003 04:45 AM (UTC)
Message
Ok, I like to think that Im farely skilled with reg exp by now, but I still cant get this... On the MUD I play there is something that shows the amount of exp gained over the total time youve played

|Exp gained | 0 |

however, this can change, but the format always is the same width

Ex:
|Exp gained | 0 |
|Exp gained | 10235320 |

I would like a trigger to match that line, but have a reg exp to gather the amount of xp total. I cant get it to match because it always changes in the amount of spaces before the second | and the digits... ive tried using * but keep getting 'Nothing to repeat at offset'
Any ideas?

ChaosMUD: chaosmud.org:23
Always looking for new players/coders. Willing to train if your willing to lear. Contact Neverwhere or just mention that I sent you.
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #1 on Thu 10 Jul 2003 08:18 AM (UTC)

Amended on Mon 14 Jul 2003 08:21 AM (UTC) by Nick Gammon

Message
I would do something like this:


^\| Exp gained \|\s+(\d+)\s+\|$


In regexps saying (something)+ means "one or more of something", and using \s means "a whitespace character", so putting it together, \s+ means one or more spaces.

Similarly \d means a digit (0 - 9).

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Neverwhere   USA  (40 posts)  Bio
Date Reply #2 on Sun 13 Jul 2003 12:58 AM (UTC)
Message
ok, but when i put the \d+ part into () it doesnt work anymore...

|\s+(\d+)\s+| <-- Doesnt match anything... should I put the \s+ 's into () also?

ChaosMUD: chaosmud.org:23
Always looking for new players/coders. Willing to train if your willing to lear. Contact Neverwhere or just mention that I sent you.
Top

Posted by David B   USA  (80 posts)  Bio
Date Reply #3 on Sun 13 Jul 2003 09:10 AM (UTC)
Message
Do you need the wildcard to put into a variable?

The \d+ doesn't save the number to a variable, so you'd have to do:

^\| Exp gained \|\s+(.*)\s+\|$

I think. It's been a while since I've had to use regular expressions like that.

My code(with a LOT of Nicks help) to fame:

sub OnAutoCombo (TriggerName, TriggerLine, arrWildCards)
dim AutoCombo
AutoCombo = split (arrWildCards (1))
Dim i, attack
for i=lbound (AutoCombo ) to ubound (AutoCombo )
Select Case AutoCombo (i)
case "rp" attack = "punch right"
case "lp" attack = "punch left"
case "s" attack = "sweep"
case "r" attack = "roundhouse"
case else attack = "" ' unknown attack type
End Select
if i = ubound (AutoCombo ) then
world.send "throw " + world.getvariable ("attacker") + " down"
else
world.send attack + " " + world.GetVariable ("attacker")
end if
next
end sub
Top

Posted by Poromenos   Greece  (1,037 posts)  Bio
Date Reply #4 on Sun 13 Jul 2003 10:35 AM (UTC)
Message
Everything returns if you enclose it in parentheses... Maybe you have to escape the pipes (|) though?

Vidi, Vici, Veni.
http://porocrom.poromenos.org/ Read it!
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #5 on Sun 13 Jul 2003 09:09 PM (UTC)
Message
Quote:

The \d+ doesn't save the number to a variable ...


It will with the brackets around it, that is why I had them.

You need to escape the "|" symbols, as I did in my earlier post, otherwise they have the meaning "this" OR "that".

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Neverwhere   USA  (40 posts)  Bio
Date Reply #6 on Mon 14 Jul 2003 08:00 AM (UTC)

Amended on Mon 14 Jul 2003 08:01 AM (UTC) by Neverwhere

Message
Quote:

^\| Exp gained \|\s+\d+\s+\|$


I dont see the brackets that you said to put there, so thats why I inquired as to why it wasnt returning anything and what should be put into brackets

ChaosMUD: chaosmud.org:23
Always looking for new players/coders. Willing to train if your willing to lear. Contact Neverwhere or just mention that I sent you.
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #7 on Mon 14 Jul 2003 08:26 AM (UTC)
Message
Hmmm - my brain must have malfunctioned there. :)

I have amended the post to put the brackets in.

However looking at your original post a bit more closely, I see you have more spaces than are obvious between the vertical bars. So it should probably read:


^\|\s*Exp gained\s*\|\s+(\d+)\s+\|$


The extra \s are to allow for the spaces on each side of "Exp gained" - by following by "*" it means zero or more, which would allow for the "Exp" being hard up against the bar.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
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.


25,988 views.

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

Go to topic:           Search the forum


[Go to top] top

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