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 4 years ago.
Improve this question
Hi i am working on a ruby on rails project wih ruby-2.5.0 and rails 5. I have a string which contains the total amount. So i need to find the total amount using regex.
String:-
"TOTAL
EFT
CHANGE
Taxable Ite.s
TOTAL includes GST
OTHER SAVINGS
0000000000
$73.26
HAIERF(RDS stm IGA
KARAWARA *AOI
TERMINAL"
Here $73.26 is the total amount. I tried /$(\d{1,2}(\.)\d{1,2})/ and /^\d{1,4}(\.\d{0,2})?$/ But its not working. Please help me with exact regex. Thanks in advance.
Updated As per the op's comment:
/TOTAL(?=((?!TOTAL).)*).*?(\$\d{1,4}(?:\.\d{1,2})?)/im
This is a compilation of both of your regex.
Regex Demo
Sample Source ( Run Here )
re = /TOTAL(?=((?!TOTAL).)*).*?(\$\d{1,4}(?:\.\d{1,2})?)/im
str = 'TOTAL $234
EFT
CHANGE
Taxable Ite.s
TOTAL includes GST
OTHER SAVINGS
0000000000
$73.26
HAIERF(RDS stm IGA
KARAWARA *AOI
TERMINAL
$83.26
Total
asdasfd
sadfasdf
$1235
'
str.scan(re) do |match|
puts match[1]
end
Related
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 3 years ago.
Improve this question
I have implemented an quiz application in swift 4.0. Here, user can enter his choice from ("one" or "1") to ("four" or "4") .
If the user can provide his choice as an integer(Eg 1,2,3, or 4)then there is no issue.
but if he provide his choice as an alphabet characters (Eg "one","two", ..), then i am facing the issues while validating correct answer.
Kindly, could anyone help me, How to convert word characters "one" into integer 1 etc..
thanks a lot in advance.
You can use NumberFormatter in this way:
let formatter = NumberFormatter()
formatter.numberStyle = .spellOut
let number = formatter.number(from: "one hundred twenty-five")
print(number) // print out 125
https://developer.apple.com/documentation/foundation/numberformatter/1408845-number
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
What can be the reason of string capitalization not working?
A database column:
t.string "name", limit: 255
Some example:
flower_name = Flower.find_by(id: 1).name #=> "chamomile©"
Trying to capitalize (got the same output):
flower_name.capitalize #=> "chamomile©"
Checking if it is string:
flower_name.is_a?(String) #=> true
capitalize works with ASCII characters only. Is there any chance your string contains non-ascii letters?
Try
flower_name.mb_chars.capitalize.to_s
mb_chars method may help you if you are using Rails >= 3.
'æ-ý'.mb_chars.upcase
=> "Æ-Ý"
If you're not using Rails, you can:
use directly active_support gem:
require 'active_support/core_ext/string/multibyte'
try unicode gem.
I hope you will find an answer in this similar question: Special character uppercase
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 5 years ago.
Improve this question
I am having a strange issue with the Neo4JClient.
The following query works
.AndWhere("((shipper.Name =~ '(?i).*" + filterTxt + ".*') OR (frm.Name =~ '(?i).*" + filterTxt + ".*') OR (to.Name =~ '(?i).*" + filterTxt + ".*'))");
but the same when I convert to the parameterized query like below:
.AndWhere("((shipper.Name =~ {searchParam}) OR (frm.Name =~ {searchParam}) OR (to.Name =~ {searchParam}))")
.WithParam("searchParam", "(?i).*" + filterTxt + ".*");
it fails to execute from within the Neo4JClient I get an exception saying connection is closed, however when I pickup the DebugQueryText generated by the Neo4JClient, and execute it on the neo4j console, it returns result.
is there something I am doing wrong with the way I am using this wildcard search?
Regrads
Kiran
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
"Rubymonk Is Pretty Brilliant".match(/ ./, 9)
How is the answer "P" calculated from this regex?
use the match method on the string
passes two arguments, a regular expression and the position in the string to begin the search.
returns the character 'P'
The criteria you posted from the Rubymonk grader answer this succinctly:
passes two arguments, a regular expression and the position in the
string to begin the search
But let's examine that in more detail. match is being passed two arguments:
/ ./, a regular expression
9, the starting position in the string
The regular expression tells us that we're looking for a space () followed by any character (.).
The starting position tells us to start at position 9 (I). So instead of applying that regex against "Rubymonk Is Pretty Brilliant", we're applying it against "Is Pretty Brilliant".
In the string "Is Pretty Brilliant", where is the first place we encounter a space followed by another character? "Is[ P]retty Brilliant", right? Thus match finds a result of P (that's space-P, matching the regex, not just P.)
To see this more clearly and to experiment further with regexes, you can try it in an irb session or in your browser using Rubular.
(Just google for RegEx + ruby, You will find explanation of regex syntax)
/ANYTHING-HERE/
Will look for ANYTHING-HERE in the text.
In Your example its (/ ./,9):
/SPACE DOT/
So it will look for space followed by single character (Dot -> single character).
9 will be "I" from the string. And that is not space, so it will go on 2 characters right. Will find space, and then will find single character "P".
That is the result.
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
I have following strings:
1) Beach Cottage (CP)
2) Beach Cottage (AP)
3) Cotta (GAP)
And I want to get substing between ( ) that is from first CP
Try this for example:
str = "Beach Cottage (CP)"
str.match(/(\((.*)\))/)[2]
you can use scan also with regx:
str = "Beach Cottage (CP)"
needed_sub_str = str.scan(/\((.*)\)/)
puts "expected sub string :: #{needed_sub_str}"
Output ::
expected sub string :: CP