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
➜ Tips and tricks
➜ 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 page
Posted by
| Fred
(11 posts) 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
| Top |
|
Posted by
| Nick Gammon
Australia (23,158 posts) 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:
Thus, it is printing two numbers.
For a start, you need to quote it, like this:
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 | Top |
|
Posted by
| Fred
(11 posts) 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? | Top |
|
Posted by
| Fred
(11 posts) Bio
|
Date
| Reply #3 on Tue 03 Jan 2006 10:49 AM (UTC) |
Message
| nice!!
thx nick
noob mistake, :P
everything just working perfect
| 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.
12,685 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top