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 am trying to figure out a regex for full name that matches the following conditions:
no number or symbol within this range: !##\$%\^&*+_=
if it is an English-like name, then:
First letter of each word is capital.
There is at least one space
It can't be all capital in one word. i.e. John McDoe can pass, John MCDOE can't.
else (other languages like Shina, Korean, Jap), all pass.
Should Pass:
Ms. Jan Levinson-Gould
Dr. Martin Luther King, Jr.
Brett D'Arras-d'Haudracey
Brüno
John Doe
John McDoe
Mary-Jo Jane Sally Smith
阿阿阿
阿阿 阿阿
Should Fail:
Fatty Mc.Error$
FA!L
#arold Newm#n
N4m3 w1th Numb3r5
john doe
JOHN DOE
John MCDOE
UPDATE
I know we can't get it 100% right. But I am trying to learn from Quora's real full name system. They freak out some people who have put in ridiculous names and increase the likelihood of people giving the real full name at the second time.
Something like this perhaps, will match any number of words:
string.split(/ +/).detect{|s| not (s[0].upcase == s[0] && s[1..-1].downcase == s[1..-1]) }
This solution depends on String#upcase and String#downcase to be able to do their stuff with international characters.
On second thought, any solution to this problem will have real-world drawbacks that are result of funny user input
EDIT, lol upvote #HamZa for http://www.kalzumeus.com/2010/06/17/falsehoods-programmers-believe-about-names/
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 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
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
Hashtags sometimes combine two or more words, such as:
content marketing => #contentmarketing
If I have a bunch of hashtags assigned to an article, and the word is in that article, i.e. content marketing. How can I take that hash tag, and detect the word(s) that make up the hashtag?
If the hashtag is a single word, it's trivial: simply look for that word in the article. But, what if the hash tag is two or more words? I could simply split the hashtag in all possible indices and check if the two words produced were in the article.
So for #contentmarketing, I'd check for the words:
c ontentmarketing
co ntentmarketing
con tentmarketing
...
content marketing <= THIS IS THE ANSWER!
...
However, this fails if there are three or more words in the hashtags, unless I split it recursively but that seems very inelegant.
Again, this is assuming the words in the hash tag are in the article.
You can use a regex with an optional space between each character to do this:
your_article =~ /#{hashtag.chars.to_a.join(' ?')}/
I can think of two possible solutions depending on the requirements for the hashtags:
Assuming hashtags must be made up of words and can't be non-words like "#abfgtest":
Do the test similar to your answer above but only test the first part of the string. If the test fails then add another character and try again until you have a word. Then repeat this process on the remaining string until you have found each word. So using your example it would first test:
- c
- co
- ...
- content <- Found a word, start over with rest
- m
- ma
- ...
- marketing <- Found a word, no more string so exit
If you can have garbage, then you will need to do the same thing as option 1. with an additional step. Whenever you reach the end of the string without finding a word, go back to the beginning + 1. Using the #abfgtest example, first you'd run the above function on "abfgtest", then "bfgtest", then "fgtest", etc.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 9 years ago.
Improve this question
I'm developing an IOS app that uses speech recognition. Since the state of the art does not provide good accuracy on recognizing single letters (random, not spelling).
I was thinking to use a set of words, one per alphabet letter, and recognize those words instead (it gives hugely improved accuracy).
In Italy, for instance, it is widely used a set of city names (for spelling purpose):
A - Ancona
B - Bari
C - Como
... and so on
My question is, an average person in USA, what set of words would use??
It is for instance the NATO alphabet? Or is there another set or sets (I could always work with a mix). The only thing I cannot do is to work with the complete English Corpus ;)
Thanks in advance,
As a pilot I would recommend the standard phonetic alphabet:
A - Alpha
B - Bravo
C - Charlie
etc.
So yes, the NATO Phonetic Alphabet.
Keep in mind though that the "average" person in the USA doesn't know this alphabet. But most would know what you meant if it's used though. The occasional time I've run into a non-pilot person trying to clarify a letter, people just make up a word that starts with the letter. There is no "standard" in the USA that non-pilots know.
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
Searching for symbols is a common in programming, especially when you are new to a language.
For example, I had a question about the :: operator in Python, and that is not searchable. People looking for things like this or Object [] (array of Objects), would not find what they want.
Why do search engines seem to ignore symbols completely? They are just characters like any others. I can see why
it would be hard to extract semantics from symbols compared to words (eg: a search engine can figure out that "find," "finds," "found" are all related, if not the same word),
but is it really that hard to search for them?
I can also see why in everyday use you'd want symbols to be ignored, but how hard would it
be to make it look for something explicitly (eg: "::" would search for ::)
Check out this article on Interpreting Google Search Queries.
Specifically, section 9
Google ignores some punctuation and special characters, including ! ?
, . ; [ ] # / # < > .
Because punctuation is typically not
as important as the text around it,
Google ignores most punctuation in
your search terms. There are
exceptions, e.g., C++ and $99.
Mathematical symbols, such as /, <,
and >, are not ignored by Google's
calculator.
[ Dr. Ruth ] returns the same results
as [ Dr Ruth ]
What if you're seeking information
that includes punctuation that Google
ignores, e.g., an email address? Just
enter the whole thing including the
punctuation.
* [ info#amazon.com ]
Be aware that web pages sometimes
camouflage email addresses to make
collecting such information difficult
for spammers. For example, on some
sites you'll find the # sign in an
email address replaced with the word
“at.”
Now we'll look at some special
characters that Google doesn't ignore.
To minimize the number of entries in the index.
A search engine doesn't have to ignore them though. For example, it seems Google Code doesn't.