Jump to content

Difficulties with Lua patterns


JeViCo

Recommended Posts

Posted (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 by JeViCo
  • Discord Moderators
Posted

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.

 

Posted
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?

Posted
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

  • Thanks 2

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...