In Ruby, how do I find all the letters after the last number in a string? [closed] - ruby-on-rails

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I'm using Ruby 2.4. I have a string with letters and numbers, something like
str = "123abc234abb"
How do I find all the letters occurring after the last number in the string? For example, if I applied the function to the above, it would yield
abb

You could use a positive lookbehind:
"123abc234abb"[/(?<=\d)?[a-zA-Z]+\z/]
#=> "abb"

Try this
str.rpartition(/\d+/).last
How does this work?
rpartition splits the string into three parts, using reverse matching
last picks the post-match part from the three results

Related

Return a column range in which a string is in a cell [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 months ago.
Improve this question
Here is an example sheet:
https://docs.google.com/spreadsheets/d/1P91qqhClA8oO3-N9OGSxrFH-6lXxttZ3IN4bIGRGjHw/edit?usp=sharing
I am trying to get the column range returned in when the string in INPUT!B1 can be seen in DATABASE!A2:A into INPUT!C1:C3
You can use FILTER() function.
=FILTER(DATABASE!A:C,DATABASE!A:A=B1)
VLookup(), Index/Match(), QUERY() all these functions will work for you.

regular expression for getting single occourance of a character from a string [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I have some alphanumeric strings. From that I have to find out those strings which satisfy the following condition,
There should be only one character in the whole string and that should be 'e'
'e' should not present at the beginning or end of the string it should be present at the middle.
I want to pick strings like 43e4234,435345e5
I can do the same thing in ruby, but as i have huge number of strings i want to go with regular expression only
This should work:
/\A[^a-z]+e[^a-z]+\z/i
It means :
Beginning of the string
at least one non-letter
'e'
at least one non-letter
end of string
Here's an example :
https://regex101.com/r/H9oza7/1
Use /^[^a-z]+e[^a-z]+$/im if you want to match lines inside a string.

What is wrong with this code for 'match' and regex? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I have a string which is something like:
ABC:Something|Hello World
I want the data after '|' character so I am using regex for it.
sample_str = "ABC:Something|Hello World"
puts sample_str.match(/[^|]*$/)
This works on rubular and returns me "Hello World" as the output, but doesn't work in my ruby code. What am I missing here? I get #<MatchData ""> in Ruby.
UPDATE: Nevermind. If I use the regex and do match on the string it works now. I was doing it other way round i.e. I did (regex).match(string) instead of (string).match(regex).
Thanks for looking!
Using regex seems excessive:
string.split('|').last
Below regex should help you.
^[\S\s]+?\|([\w\s]+)$
Dont forget to select global and multiline options.
Look at the regex demo here.

Wrong regular expression for phone format [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
There is the following regular expression to describe regular expression:
validates :phone, format: { with: /\A(\+7|8)[0-9]{10}\z/ }
'89277777777' must match this expression, '+79277777777' must too. But I have got 'invalid phone' message always. How can I fix it? Thanks.
If all you want to do is a simple way to validate an international number, which may or may not start with a + followed by either a 7 or an 8, followed by 10 more digits, then this regex should do the trick:
\A\+?[78]\d{10}\z
Debuggex Demo
If my assumptions are incorrect, let me know in the comments and we'll work on a better solution.
Note: don't forget to surround the regex with // -- I didn't do that here due to the use of Debuggex

Make lowercase letters in a string uppercase [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Are there any methods for taking a string and converting all lowercase letters to uppercase?
I was thinking of making a for-loop to run through, check each character, see if it is in range 0061-007A (lowercase letters) and just subtracting 26 (base 16) (converts to the uppercase counterpart) from the unicode code and adding that character back to the string.
But I figured I'd check if there is a simpler method already out there... googled but couldn't find anything... I'm sure I could use a 1x1 UIWebView and load some javascript (that does this) with my string into the UIWebView but there has got to be something already in Objective-C other than the manual approach I first mentioned right?
You do not need a loop - you can use either
NSString *upper = [src uppercaseString];
or
NSString *upper = [src uppercaseStringWithLocale:myLocale];
for targeting a specific locale.

Resources