JeViCo Posted October 13, 2018 Share Posted October 13, 2018 (edited) Hello everyone. I've recently tried to make roleplay nickname pattern (example: Nicolas_Cage) but it doesn't work properly addCommandHandler("checkName",function(pl) local name = getPlayerName(pl) if string.match(name,"(%u?)(%l+)%_(%u?)(%l+)") then outputChatBox("rp nickname") else outputChatBox("nonrp nickname") end end) I can use Nikolas_CAgE and it'll match i used this and this wikis What am i doing wrong? Edited October 13, 2018 by JeViCo Link to comment
Gordon_G Posted October 13, 2018 Share Posted October 13, 2018 I've never understood lua's patterns too, gonna be helpful for me too Link to comment
Discord Moderators Pirulax Posted October 13, 2018 Discord Moderators Share Posted October 13, 2018 Here's your magic pattern. "(%u%l+)_(%u%l+)$" The '?' was the problem, since, as the manual describes, it'll make that :~(ex.: %u) optional, also I added a '$' too. Link to comment
JeViCo Posted October 14, 2018 Author Share Posted October 14, 2018 17 hours ago, Pirulax said: "(%u%l+)_(%u%l+)$" same result Link to comment
JeViCo Posted October 15, 2018 Author Share Posted October 15, 2018 21 hours ago, SaNoR said: ^%u(%l+)_%u(%l+)$ it works! Thank you. So how did you do that? ( ) means subpattern and ^ at the beginning and $ at the end of string mean - 'match whole string from the start till the end' Am i right? Link to comment
SaNoR Posted October 15, 2018 Share Posted October 15, 2018 3 minutes ago, JeViCo said: it works! Thank you. So how did you do that? ( ) means subpattern and ^ at the beginning and $ at the end of string mean - 'match whole string from the start till the end' Am i right? Yes 2 Link to comment
JeViCo Posted October 15, 2018 Author Share Posted October 15, 2018 1 minute ago, SaNoR said: Yes Thank you so much. Now i understand patterns a little bit more Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now