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


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Tips and tricks
. . -> [Subject]  A regexp question, how to capture 123,456 ?

A regexp question, how to capture 123,456 ?

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


Posted by Fred   (11 posts)  [Biography] bio
Date Tue 03 Jan 2006 06:58 AM (UTC)
Message
i'm trying to capture this kind of information
ABC 123,456 (100%) or ABC 1,234,567 (100%), ABC 12 (100%)

My trigger is
ABC(.*)\(.*

here is the problem, 1% = 123 456, I have a missing "," sign here.
when i try to assign this value to a variable, it will equal to 123.
the value which i'm looking for is either "123,456" or "123456"

btw, string.len(%1) = 3
print(%1) = 123 456
[Go to top] top

Posted by Nick Gammon   Australia  (23,016 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Tue 03 Jan 2006 10:31 AM (UTC)
Message
Your problem here is partly that you haven't quoted %1.

This is being fed to Lua as:


print(123, 456)


Thus, it is printing two numbers.

For a start, you need to quote it, like this:


print("%1")  --> 123,456


However now your problem is you have 2 numbers inside a string. A simple "gsub" to replace commas by nothing will convert it to a single number (inside a string):


num = string.gsub ("%1", ",", "")
print (num)  --> 123456


Finally, to do arithmetic on it you should probably do "tonumber" on it, to make sure it is being considered as a number:


num = tonumber (string.gsub ("%1", ",", ""))
print (num) --> 123456



- Nick Gammon

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

Posted by Fred   (11 posts)  [Biography] bio
Date Reply #2 on Tue 03 Jan 2006 10:41 AM (UTC)
Message
finally, I figured out I should call script function rather than setvariable under trigger...
it's so inconvenience.

and any idea to trim out the "," sign?
[Go to top] top

Posted by Fred   (11 posts)  [Biography] bio
Date Reply #3 on Tue 03 Jan 2006 10:49 AM (UTC)
Message
nice!!
thx nick
noob mistake, :P
everything just working perfect
[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.


11,080 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 HostDash]