View Full Version : Loading portions of a string into variables - RegEx / MatchFind
JohnDoe
07-07-2010, 11:14 PM
Trying to load two parts of a string into two variables. I suck at RegEx and haven't been able to figure out how to do it that way. So, I've been using matchfind. Unfortunately, it's not working reliably (not matching in some cases). The fact that I can't figure this out is frustrating the hell out of me.
Anyone able to help me out with the correct RegEx to load the gem name and the number of gems being asked for from the NPC response below?
Praeteria says, "Ah, so you're from the Adventurer's Guild? Yes, I do have a task for you. I've recently received several orders from customers interested in purchasing a star ruby. Unfortunately, I do not have quite enough inventory on hand to meet this demand. I'd like for you to go round up 6 of them for me. You can SELL them to me as you find them."
Here's the matchfind statement I'm using
bounty_gem, bounty_gemamt = matchfind "I've recently received several orders from customers interested in purchasing ?. Unfortunately, I do not have quite enough inventory on hand to meet this demand. I'd like for you to go round up ? of them for me."
SpiffyJr
07-08-2010, 12:05 AM
loop {
line = get
if line =~ /interested in purchasing [a|an] (.*)\. Unfortunately/
echo "Gem is #{$1}"
end
if line =~ /to go round up (\d+) of them for me/
echo "Gem count is #{$1}"
end
}
You could do it with one regex but I didn't want to type all that out. Result:
>;test
--- Lich: test active.
>;e send_to_script('test', "Praeteria says, \"Ah, so you're from the Adventurer's Guild? Yes, I do have a task for you. I've recently received several orders from customers interested in purchasing a star ruby. Unfortunately, I do not have quite enough inventory on hand to meet this demand. I'd like for you to go round up 6 of them for me. You can SELL them to me as you find them.\"")
--- Lich: exec1 active.
[exec1: Sent to test -- 'Praeteria says, "Ah, so you're from the Adventurer's Guild? Yes, I do have a task for you. I've recently received several orders from customers interested in purchasing a star ruby. Unfortunately, I do not have quite enough inventory on hand to meet this demand. I'd like for you to go round up 6 of them for me. You can SELL them to me as you find them."']
--- Lich: exec1 has exited.
[test: Gem is star ruby]
[test: Gem count is 6]
JohnDoe
07-08-2010, 12:30 AM
Thanks - very helpful. For some reason this line doesn't seem to have the gem pulled out:
Praeteria says, "Ah, so you're from the Adventurer's Guild? Yes, I do have a task for you. I've recently received several orders from customers interested in purchasing some bright bluerock. Unfortunately, I do not have quite enough inventory on hand to meet this demand. I'd like for you to go round up 6 of them for me. You can SELL them to me as you find them."
I changed the following to account for the "some" being used to reference the bright bluerock:
if line =~ /interested in purchasing [a|an|some] (.*)\. Unfortunately/
Gem number is being extracted. Gem name is not. Any idea what I'm missing?
Tillmen
07-08-2010, 12:36 AM
Use
an?
instead of
[a|an]
The question mark after the n makes it optional, so it matches both "a" and "an". The brackets match any one character inside them. He meant
(?:a|an)
Which would also work.
JohnDoe
07-08-2010, 12:47 AM
Ah got it, (?:a|an|some) seems work work. Thanks. Been beating my head against the wall on this one for some reason. Appreciate the responses.
SpiffyJr
07-08-2010, 01:05 AM
Use
an?
instead of
[a|an]
The question mark after the n makes it optional, so it matches both "a" and "an". The brackets match any one character inside them. He meant
(?:a|an)
Which would also work.
:yeahthat:
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.