Created
September 10, 2019 18:59
-
-
Save staycreativedesign/4c924bc4abee3a9fa6561987262b0ca5 to your computer and use it in GitHub Desktop.
why is this match getting nil?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[5] pry(main)> receipt_number = receipt["Reference Number(s)"] | |
=> "121961|501526|121961|501526" | |
[6] pry(main)> receipt_number = receipt["Reference Number(s)"].match(/"\K\d+/) | |
=> nil | |
https://rubular.com/r/ML1ypdresB9CKY |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A more readable regex that works if
receipt_number
can't have multiple lines:Another approach that's easier to read and understand but less efficient if the string could be very long (hundreds or more).
Prefer readability over efficiency when the efficiency gain isn't significant to the business goals of what you're building.