Hi All,
I have an issue in parsing regular expression and im new to
regexp.
Varaiable = “Internation tip ($25 fee)”
The $25 might vary each time, it might be $5, $ 10 so on
I tried doing something like this which didnt work, kindly help
variable = “Internation tip (regexp:$[0-9][0-9]+ fee)”
i want the regular expression to aid both single digit or multi digit
currency.
Hi All,
I have an issue in parsing regular expression and im new to
regexp.
Varaiable = “Internation tip ($25 fee)”
The $25 might vary each time, it might be $5, $ 10 so on
I tried doing something like this which didnt work, kindly help
variable = “Internation tip (regexp:$[0-9][0-9]+ fee)”
i want the regular expression to aid both single digit or multi digit
currency.
Cheers
As Stefano C. pointed out $,(,) must be escaped.
To allow any number of digits, and at least 1 use \d{1,).
Moreover you must match different descriptions and check for null
values.
Example:
‘$’ says that you are looking for the ‘$’ character not the end of the
line…which is what I think you are looking for. Then you have the
[0-9]{1,} which says that you are looking for at least one number, but
that there could be more. This should work for you, but you can also
check out these links :
On Fri, Oct 8, 2010 at 8:40 AM, Idealone I. [email protected]
wrote:
Hi All,
I have an issue in parsing regular expression and im new to
regexp.
Varaiable = “Internation tip ($25 fee)”
First of all, “Variable” is a constant. You need to make the name
start with a lowercase letter.
The $25 might vary each time, it might be $5, $ 10 so on
I tried doing something like this which didnt work, kindly help
variable = “Internation tip (regexp:$[0-9][0-9]+ fee)”
i want the regular expression to aid both single digit or multi digit
currency.
There is a simple approach and a more robust approach:
irb(main):008:0> v = “Internation tip ($25 fee)”
=> “Internation tip ($25 fee)”
irb(main):009:0> v[/\d+/].to_i
=> 25
irb(main):010:0> v[/\AInternation tip ($(\d+) fee)\z/, 1].to_i
=> 25
The first regexp extracts any number, i.e. this works with differently
formatted strings as long as there is at least one digit somewhere.
The second one checks that your string actually follows the pattern
you described.
‘$’ says that you are looking for the ‘$’ character not the end of
the line…which is what I think you are looking for. Then you have
the [0-9]{1,} which says that you are looking for at least one
number, but that there could be more. This should work for you, but
you can also check out these links :
Instead of [0-9] you can type \d and instead of {1,} you can type + -
much less hassle.
And then of course you also need a capturing group to get at the digits.
Cheers
robert
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.