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
In ruby i have a string like this:
str= 43,69 €
Is possible with a regex obtain 43,69 ?
I have tried with:
/\d+(?:\.\d+)?/
but the output is incorrect: 43.0
This should work
/\d+(?:[.,]\d+)?/
The [.,] part matches decimal separator for a dot or a comma. If you are sure thet decimal separator will be a comma, you can use this:
/\d+(?:,\d+)?/
Related
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 2 years ago.
Improve this question
I am decoding data as shown on the right window and then using it to output a model via the initializer defined in the middle one. However, when I try to use it, I am being told that I am passing the wrong argument type.
Why is it that I am getting an error that the initializer is expecting a String, if I have defined it in the Model (the middle screen) to explicitly expect a [String] ?
Screenshot
The two of the arguments - genre and backgroundImage - are swapped, which causes the issue with the Initializer.
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
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 7 years ago.
Improve this question
I am new to ruby and would like to create a simple method to convert a series of unix timestamps into datetime format. Currently, what I am doing (in console on my terminal is)
def foo(x)
Time.at(:x)
end
Then I would pass in foo(1315922016). But I get an error
Can't convert Symbol into an exact number
How can I revise my ruby code to allow it to accept an integer which then is put into Time.at method for conversion?
This should be simple call as:
def foo(x)
Time.at(x)
end
Hope that helps!
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.
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
This is the best reduced case of I am seeing
NSString * test = #"??( ";
NSLog(#"'%#'", test);
console> '['
I have a work around
NSString * test = #"\x3f\x3f(";
NSLog(#"'%#",test);
console> '??('
It seems like this is likely caused by string interpolation or similar process in the NSString object vivification. I'm posting this question for two reasons.
1) anyone happen to know what is actually causing this?
2) I didn't find anything on this 'feature' of NSString and it took me an hour to track down the bug, so this is just a bread crumb for future programmers. Using the hex code for the character was the work around.
NSlog("'%#'", test); is syntactically incorrect. How are you compiling it with this syntax error?
If I change it to NSLog(#"'%#'", test);, it works correctly (note the string literal denoting # and the uppercase L in NSLog).