I am working on an application where I need to pass on the anything before "@" sign from the user's email address as his/her first name and last name. For example if the user has an email address "[email protected]" than when the user submits the form I remove "@example.com" from the email and assign "user" as the first and last name.
I have done research but was not able to find a way of doing this in Ruby. Any suggestions ??
You can split on "@" and just use the first part.
email.split("@")[0]
That will give you the first part before the "@".
To catch anything before the @ sign:
my_string = "[email protected]"
substring = my_string[/[^@]+/]
# => "user"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With