generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: How to take out just letters from a string?

Previous Thread :: Next Thread 
IceFromSpace is not online. IceFromSpace
Joined: 12 Dec 2015
Total Posts: 710
23 Jan 2016 08:55 PM
lets say we have a string... "b87b9s08b"

how would you remove all letters from a string but keep the numbers, and having the numbers in the correct order

it should wind up like this

"87908"

Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
23 Jan 2016 08:58 PM
You can do:

string.gsub(str, "%a+", "")
Report Abuse
IceFromSpace is not online. IceFromSpace
Joined: 12 Dec 2015
Total Posts: 710
23 Jan 2016 08:59 PM
what is %a+
Report Abuse
cody123454321 is not online. cody123454321
Joined: 21 Nov 2009
Total Posts: 5408
23 Jan 2016 08:59 PM

local gatherNumbers = function(str)
local out = ""
for v in str:gmatch("[^%D]+")do
out = out .. v
end
return out
end
Report Abuse
AbstractMadness is not online. AbstractMadness
Joined: 22 Dec 2014
Total Posts: 20425
23 Jan 2016 09:00 PM
local str = "dnd93md93f"

str = str:gsub("%a","") -- %a is an uppercase or lowercase letter



#code R+ | local RAP = "426,386"; local robux = "R$9,003"
Report Abuse
phoenix53124 is not online. phoenix53124
Joined: 25 Feb 2009
Total Posts: 4889
23 Jan 2016 09:00 PM
It's called a pattern. It means 1 or more alphabetical characters. 'w' is alphanumeric, 'b' is between and followed by two characters (like between parentheses '%b()') and more. Just search for string patterns on the wiki.
Report Abuse
AbstractMadness is not online. AbstractMadness
Joined: 22 Dec 2014
Total Posts: 20425
23 Jan 2016 09:01 PM
my bad, I forgot the + sign. Add it after the %a+.



#code R+ | local RAP = "426,386"; local robux = "R$9,003"
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
23 Jan 2016 09:01 PM
%a is the pattern for all letters (a-zA-Z)
You can also do

gsub(str, "[^%d]+", "") too to remove any none digits
Report Abuse
IceFromSpace is not online. IceFromSpace
Joined: 12 Dec 2015
Total Posts: 710
23 Jan 2016 09:01 PM
Thx but what does [^%D]+ mean
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
23 Jan 2016 09:01 PM
non-digits*
Report Abuse
cody123454321 is not online. cody123454321
Joined: 21 Nov 2009
Total Posts: 5408
23 Jan 2016 09:02 PM
http://wiki.roblox.com/?title=Patterns
Report Abuse
128Gigabytes is not online. 128Gigabytes
Joined: 17 Apr 2014
Total Posts: 3616
23 Jan 2016 09:02 PM
Do you want to take out all the letters or do you want to keep all the numbers?

Take out all the letters changes ABC?.,123 to ?.,123

Keep all the numbers changes ABC?.,123 to 123

string.gsub(input, "%D+", '')
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
23 Jan 2016 09:02 PM
"[^%D]+" Look up string patterns. This one does not work. Cnt's works, but I would do %D+ because that (IMO) is less messy and work-around-ish than those carrot brackets.
Report Abuse
AbstractMadness is not online. AbstractMadness
Joined: 22 Dec 2014
Total Posts: 20425
23 Jan 2016 09:02 PM
^ anchors to the beginning of the string, %D is all NON-digits.



#code R+ | local RAP = "426,386"; local robux = "R$9,003"
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
23 Jan 2016 09:03 PM
^ doesn't anchor to the beginning of a string if it's in a class.
Report Abuse
AbstractMadness is not online. AbstractMadness
Joined: 22 Dec 2014
Total Posts: 20425
23 Jan 2016 09:08 PM
class?



#code R+ | local RAP = "427,315"; local robux = "R$9,003"
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
23 Jan 2016 09:09 PM
Character class, also known as character set.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
23 Jan 2016 09:10 PM
[%w_] is a custom class that matches either a alphanumerical character or an underscore
The "^" inverts the class, so [^%w] is non-alpha numerical characters (%W accomplishes this as well)
Report Abuse
AbstractMadness is not online. AbstractMadness
Joined: 22 Dec 2014
Total Posts: 20425
23 Jan 2016 09:11 PM
Ohhhh... that's the complicated way for just capitalizing it to get the opposite effect...



#code R+ | local RAP = "427,315"; local robux = "R$9,003"
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
23 Jan 2016 09:13 PM
Well I mean you sometimes have to do it.
Like in the case of inverting multiple things or something that's not a "default" class.

[^abc] will match anything NOT a, b, or c
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
23 Jan 2016 09:16 PM
Why don't regular expressions support left-recursion? For that matter, why doesn't Lua support regular expressions?! I dislike string patterns, they are weak.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
23 Jan 2016 09:19 PM
Lua's string pattern 'library' is small, regex is gigantic. That's probably the biggest reason why regex is not in Lua
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
23 Jan 2016 09:19 PM
Why do I ask questions that I expect answers to right before going to bed? Good night, have fun eating jell-o and hyper chuckwallas.
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
23 Jan 2016 09:20 PM
Ah, that makes sense. Good night again, and have fun eating fluorescent armadillos.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image