[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]  Complex regex question
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Complex regex question

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


Posted by Poromenos   Greece  (1,037 posts)  [Biography] bio
Date Tue 08 Jun 2004 08:22 PM (UTC)
Message
The MUD I play on sends this:
You have 102,123,543,534 gold coins.
Is there any way to make a regex that returns the number of coins regardless of commas? So far I have this:
((\d+)\,|)((\d+)\,|)(\d+)
and i return %2%4%5 but I was wondering if there was a better way that matches on more commas/whatever.

Vidi, Vici, Veni.
http://porocrom.poromenos.org/ Read it!
[Go to top] top

Posted by Flannel   USA  (1,230 posts)  [Biography] bio
Date Reply #1 on Tue 08 Jun 2004 08:38 PM (UTC)
Message
This is assuming you want to get rid of the commas in your return? Otherwise you could simply include the commas in the regexp ([0-9\,]+). Or group your numbers into threes, or whatnot.

~Flannel

Messiah of Rose
Eternity's Trials.

Clones are people two.
[Go to top] top

Posted by Nick Gammon   Australia  (21,417 posts)  [Biography] bio   Forum Administrator
Date Reply #2 on Tue 08 Jun 2004 09:51 PM (UTC)
Message
I don't think you will make a regexp that will automatically make each one of an indefinitely long list assign to different wildcard numbers. So, I would do something simple and then Split it.

eg.

(?P<coins>((\d{1,4},)*)(\d{1,4}))

This would match any number of repetitions (zero or more with the commas, followed by the last block) and save as wildcard "coins".

Then you could do:

x = Split ("%<coins>", ",")




- Nick Gammon

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

Posted by Poromenos   Greece  (1,037 posts)  [Biography] bio
Date Reply #3 on Tue 08 Jun 2004 11:03 PM (UTC)
Message
Right, Flannel, I want to get rid of the commas. And Nick, I don't want to use scripting if possible, that's why I'm looking for the regex. As you said, it would assign each one to a different number, so I assume it's not possible? I guess I'll keep using this one, it's not as if anyone has anything bigger than billions anyway...

Vidi, Vici, Veni.
http://porocrom.poromenos.org/ Read it!
[Go to top] top

Posted by Flannel   USA  (1,230 posts)  [Biography] bio
Date Reply #4 on Tue 08 Jun 2004 11:04 PM (UTC)

Amended on Tue 08 Jun 2004 11:06 PM (UTC) by Flannel

Message
Nick, why you using \d{1,4}? Why not 1,3? You shouldnt have a grouping of more than three, right?

And Poromenos, I dont think youll be able to get rid of the commas, and match any number, in one regexp. Because for each set, you'd have a different wildcard for it.

Unless you could use forward looking things, since they dont match, to maybe look, but not match, the commas, but still, I dont see how that would work.

~Flannel

Messiah of Rose
Eternity's Trials.

Clones are people two.
[Go to top] top

Posted by Nick Gammon   Australia  (21,417 posts)  [Biography] bio   Forum Administrator
Date Reply #5 on Wed 09 Jun 2004 01:45 AM (UTC)
Message
Quote:

Nick, why you using \d{1,4}? Why not 1,3?


Sorry, I misunderstood the original question. I thought he was talking about piles of coins, not one very large pile.

In that case, you really want a regexp that matches like mine did, but use scripting to remove the commas, eg.

x = CInt ( world.Replace ("%<coins>", ",", ""))

That takes the number, strips the commas and converts to an integer (probably an integer would be too small, but that is the general idea).

However doing it without scripting?

Probably your original idea would work, after all how many coins are you really expecting? About 6 groups (3 digits each) is likely to be the most the MUD could possibly output.

- Nick Gammon

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


3,701 views.

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.

[Home]


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]