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
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 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 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 does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 9 years ago.
Improve this question
I am inserting some keyword like Don't , has'nt in Sqlite which is not inserted.any one have idea about it.
Use ' as escape character and insert it like this:
dont''t
Documentation:
A single quote within the string can be encoded by putting two single quotes in a row - as in Pascal
In case you are using an API to connect with Sqlite, instead of manipulating the original string a better approach would be to use sqlite3_bind_text() function to bind a value to a ? placeholder in the SQL. Thanks to #Rob for pointing this out.
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.
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 want to make a regular express to parse out the value (29.0) from this node:
"<currentPrice currencyId="USD">29.0</currentPrice>"
in an xml document. And I would like the value (price) of each and every instance of that node. There is no limit or minimum to what price could be.
Use Nokogiri::XML(myXml).xpath('//currentPrice/text()').map(&:to_s)
Using a regexp to parse XML makes certain infant deities cry.
Here is another way to answer this question, by using Ruby's standard Library REXML
require 'rexml/document'
#doc = REXML::Document.new('<currentPrice currencyId="USD">29.0</currentPrice>')
#doc.get_elements("//currentPrice")[0].text # => "29.0"