-
April 2nd, 2020, 14:26 #1
String.match return multiple text even if not all exist
Folks,
Never liked regex but I used it, though Lua doesn't use regex, it uses pattern matching
Inside Traveller when you drop a skill onto an existing skill it increases that Skill by 1.
But specialised skills don't work.
For example:
Melee (unarmed) 1, Carouse 2
I have it making Carouse 3 if Carouse is dragged over the NPC skills, using
Code:sSkill, nExistingLevel = string.match(sSkillsCurrently, "(" .. sNewSkill .. ") (%d*)");
Code:sSkill, sSpecialism, nExistingLevel = string.match(sSkillsCurrently, "(" .. sNewSkill .. ") (%s+) (%d*)");
Cheers,
MBMRuleset and much more content built for FGU.
Come join me on Twitter at: https://twitter.com/MadBeardMan to see what I'm up to!
-
April 2nd, 2020, 14:40 #2
I tend to test for the string with the word in brackets first and then if there isn't a match try for a match without brackets.
To check for three captures, with the middle one being a single word consisting of alphanumberic characters within brackets, try this:
Code:"(" .. sNewSkill .. ") %((%w+)%) (%d*)"
Code:"(" .. sNewSkill .. ") %([(%w%s]+)%) (%d*)"
Code:"(" .. sNewSkill .. ") (%d*)"
Last edited by Trenloe; April 2nd, 2020 at 14:43.
Private Messages: My inbox is forever filling up with PMs. Please don't send me PMs unless they are actually private/personal messages. General FG questions should be asked in the forums - don't be afraid, the FG community don't bite and you're giving everyone the chance to respond and learn!
-
April 2nd, 2020, 17:25 #3
Hi Chap,
Super, thanks for this. Works nicely. The specialisation would only be single, so 'Gun Combat (slug)' or 'Drive (Wheeled)'.
Hope you and yours are safe and sound wherever in the world you are!
Cheers,
MBMRuleset and much more content built for FGU.
Come join me on Twitter at: https://twitter.com/MadBeardMan to see what I'm up to!
-
April 2nd, 2020, 17:55 #4
Hi Trenloe,
Maybe you can answer this one then.
Runtime Notice: s'sSkillsCurrently' | s'Medic 2, Melee (unarmed) 0, Pilot 0'
Runtime Notice: s'sOldSkillLevel' | s'Melee (unarmed) 0'
Runtime Notice: s'sNewSkillLevel' | s'Melee (unarmed) 1'
Runtime Notice: s'sNewSkills' | s'Medic 2, Melee (unarmed) 0, Pilot 0'
Code:Debug.console('sOldSkillLevel', sOldSkillLevel); Debug.console('sNewSkillLevel', sNewSkillLevel); sNewSkills = sSkillsCurrently:gsub(sOldSkillLevel, sNewSkillLevel); Debug.console('sNewSkills', sNewSkills); DB.setValue(vTarget, "skills", "string", sNewSkills);
Cheers,
MBMRuleset and much more content built for FGU.
Come join me on Twitter at: https://twitter.com/MadBeardMan to see what I'm up to!
-
April 2nd, 2020, 18:42 #5
The brackets are reserved characters in regular expressions - you'll need to escape those in the strings used in string.gsub.
This is something I've done recently for Pathfinder 2 automation development (still in testing for those who are interested):
Code:-- Replace reserved Regex characters with escaped characters sSearchAutomationString = string.gsub(sAutomationString, "%+", "%%%+"); sSearchAutomationString = string.gsub(sSearchAutomationString, "%-", "%%%-"); sSearchAutomationString = string.gsub(sSearchAutomationString, "%(", "%%%("); sSearchAutomationString = string.gsub(sSearchAutomationString, "%)", "%%%)")
Private Messages: My inbox is forever filling up with PMs. Please don't send me PMs unless they are actually private/personal messages. General FG questions should be asked in the forums - don't be afraid, the FG community don't bite and you're giving everyone the chance to respond and learn!
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks