I want to remove any leading and trailing non-alphabetic character in my string.
for eg. ":----- pt-br:-"
, i want "pt-br"
Thanks
result = subject.gsub(/\A[\d_\W]+|[\d_\W]+\Z/, '')
will remove non-letters from the start and end of the string.
\A
and \Z
anchor the regex at the start/end of the string (^
/$
would also match after/before a newline which is probably not what you want - but that might not matter in this case);
[\d_\W]+
matches one or more digits, the underscore or anything else that is not an alphanumeric character, leaving only letters.
|
is the alternation operator.
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