Most audios that have been amplified have 'loud' in the title. I have a boombox and I want to prevent these audios being played. I have made it so that if it finds 'loud' in the title or description then it gets refused. The ROBLOX studio search (CTRL+F) lets you search for a whole word only so it can't be included in a word, as 'loud' is in 'cloud'. I can't think of a way to do this, my current code searches for the word, but not just the word, so these are the results when searching for loud:
1 | 'cloud' --> true |
2 | 'cloud.' --> true |
3 | 'louder' --> true |
4 | 'louder.' --> true |
5 | 'loud' --> true |
6 | 'loud.' --> true |
But these are the results I want:
1 | 'cloud' --> false |
2 | 'cloud.' --> false |
3 | 'louder' --> false |
4 | 'louder.' --> false |
5 | 'loud' --> true |
6 | 'loud.' --> true |
I can't work out a method for achieving this, I hope you can help!
You should 1st look at Character Classes as you will need to understand how string patterns work.
The main problem is knowing when a new word has started which is why cloud
would match.
The pattern %f[%l]loud%f[%L]%.?
this will look for the whole word loud in lower case %l
I have also added '%.?% which will look for 0 or one match of the literal '.'
My testing:-
01 | local test = { |
02 | 'loud' , 'loud.' , 'Loud' , 'Loud.' , |
03 | ' loud' , ' loud.' , ' Loud' , ' Loud.' , |
04 | ' loud ' , ' loud. ' , ' Loud ' , ' Loud. ' , |
05 | 'cloud' , 'a loud' , 'very' |
06 | } |
07 |
08 | local pattern = '%f[%l]loud%f[%L]%.?' |
09 |
10 | for i, str in pairs (test) do |
11 | local match = str:match(pattern) |
12 | if match then |
13 | print ( 'String found index' , i, 'String ' , str, 'Res' , match) |
14 | else |
15 | print ( 'Did not find' , str) |
16 | end |
17 | end |
I hope this helps.
Hey, this is gonna be a short answer because, I literally have like 1 minute but, here are the scripts that I managed to come up with: If you don't understand anything please post it in the comment below.
01 | -- Won't print anything |
02 | local matching = "loud" |
03 | local name = "cloud" |
04 |
05 | for w in string.gmatch(name, matching) do |
06 | if #w = = #name then |
07 | print (w) |
08 | end |
09 | end |
10 |
11 | -- Will print "loud" |
12 | local matching = "loud" |
13 | local name = "loud" |
14 |
15 | for w in string.gmatch(name, matching) do |
16 | if #w = = #name then |
17 | print (w) |
18 | end |
19 | end |
Thank you for your time and I am sorry this is a really messy answer but, it should be helpful. Don't forget if you don't understand anything, comment below.
~~ KingLoneCat