JeViCo Posted October 13, 2018 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
Gordon_G Posted October 13, 2018 Posted October 13, 2018 I've never understood lua's patterns too, gonna be helpful for me too Gordon#6977
Moderators Pirulax Posted October 13, 2018 Moderators 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.
JeViCo Posted October 14, 2018 Author Posted October 14, 2018 17 hours ago, Pirulax said: "(%u%l+)_(%u%l+)$" same result
JeViCo Posted October 15, 2018 Author 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?
SaNoR Posted October 15, 2018 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
JeViCo Posted October 15, 2018 Author Posted October 15, 2018 1 minute ago, SaNoR said: Yes Thank you so much. Now i understand patterns a little bit more
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