Here is an example:
s.match(/+[^@]*/)
Result => "+subtext"
The thing is, i do not want to include "+" in there. I want the result to be "subtext", without the +
You can use parentheses in the regular expression to create a match group:
s="[email protected]"
s =~ /\+([^@]*)/ && $1
=> "subtext"
You could use a positive lookbehind assertion, which I believe is written like this:
s.match(/(?<=\+)[^@]*/)
EDIT: So I just noticed this is a Ruby question, and I don't know if this feature is in Ruby (I'm not a Ruby programmer myself). If it is, you can use it; if not... I'll delete this.
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