Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #19521
| From | Stefan Weiss <krewecherl@gmail.com> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: Help creating 'simple' regex |
| Date | 2013-04-28 19:41 +0200 |
| Organization | albasani.net |
| Message-ID | <kljn0a$b20$1@news.albasani.net> (permalink) |
| References | (3 earlier) <27oon89p058st28cgicdg93c3sdcoghpth@4ax.com> <XnsA1B05F1BB33B3eejj99@194.109.133.133> <4vmpn8lv41nhapq42a8q1fapqdh4qqr62h@4ax.com> <kliqbp$f8i$1@news.albasani.net> <9bkqn8hmr8a2uli9adse19j9ld7ohpf4tj@4ax.com> |
On 2013-04-28 18:53, Joey@still_Learning.invalid wrote:
> Stefan Weiss wrote:
>>If the search string is empty, it will always match, because every
>>possible haystack string contains the empty string. That's a feature,
>>not a bug. If you don't want that, don't search for an empty string.
>
> That would always be my preference, but some of my users are damned-fools
> who hit the 'do-it' button without thinking. I want to catch their error.
Not a problem; you have to validate all user input anyway.
var str = prompt("Search for:").trim(); // or equivalent fallback
if (str) {
if (moreValidations(str)) {
// perform search
} else {
// display warning
}
} else {
// do nothing, treating no input as abort
}
> We have seen our users (who are medical professionals!) do the dumbest
> things imaginable. They have been to enter one or more spaces preceding
> and within the input strings, etc. : ' Jane Doe ' is typical.
So you're not looking to match exact strings... good to know.
If this is for a name search, you'll probably want separate fields for
first and last names.
trim() takes care of the spaces on both sides in " Jane Doe ", but if
you want to account for the spaces in the middle, you'll have to do more
work than \binput\b.
Even the \b markers can lead to incorrect matching in certain cases. For
example, \bRhys\b would incorrectly match Rhys-Davies. There are other
gotchas with \b as well (O'Neill, LeFêvre, ... all contain word boundaries).
In any case, if you're dynamically building a regex from user input, you
can start from the "new RegExp()" example I posted earlier.
- stefan
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Help creating regex "Joey@still_Learning.invalid" <Joey@still_Learning.invalid> - 2013-03-20 11:47 -0700
Re: Help creating regex Danny <dann90038@gmail.com> - 2013-03-20 12:08 -0700
Re: Help creating regex "Joey@still_Learning.invalid" <Joey@still_Learning.invalid> - 2013-03-20 12:18 -0700
Re: Help creating regex Jim T. <x@y.z> - 2013-03-20 15:11 -0500
Re: Help creating regex "Joey@still_Learning.invalid" <Joey@still_Learning.invalid> - 2013-03-20 12:19 -0700
Re: Help creating regex Dr J R Stockton <reply1300@merlyn.demon.co.uk.invalid> - 2013-03-21 20:20 +0000
Help creating 'simple' regex "Joey@still_Learning.invalid" <Joey@still_Learning.invalid> - 2013-04-27 10:56 -0700
Re: Help creating 'simple' regex JJ <duh@nah.meh> - 2013-04-28 02:27 +0700
Re: Help creating 'simple' regex "Joey@still_Learning.invalid" <Joey@still_Learning.invalid> - 2013-04-27 16:39 -0700
Re: Help creating 'simple' regex "Joey@still_Learning.invalid" <Joey@still_Learning.invalid> - 2013-04-28 09:36 -0700
Re: Help creating 'simple' regex "Joey@still_Learning.invalid" <Joey@still_Learning.invalid> - 2013-04-29 01:41 -0700
Re: Help creating 'simple' regex Stefan Weiss <krewecherl@gmail.com> - 2013-04-27 22:27 +0200
Re: Help creating 'simple' regex Stefan Weiss <krewecherl@gmail.com> - 2013-04-27 22:34 +0200
Re: Help creating 'simple' regex "Joey@still_Learning.invalid" <Joey@still_Learning.invalid> - 2013-04-27 16:39 -0700
Re: Help creating 'simple' regex "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-04-28 09:20 +0200
Re: Help creating 'simple' regex "Joey@still_Learning.invalid" <Joey@still_Learning.invalid> - 2013-04-28 01:22 -0700
Re: Help creating 'simple' regex Stefan Weiss <krewecherl@gmail.com> - 2013-04-28 11:32 +0200
Re: Help creating 'simple' regex "Joey@still_Learning.invalid" <Joey@still_Learning.invalid> - 2013-04-28 09:53 -0700
Re: Help creating 'simple' regex Stefan Weiss <krewecherl@gmail.com> - 2013-04-28 19:41 +0200
Re: Help creating 'simple' regex "Joey@still_Learning.invalid" <Joey@still_Learning.invalid> - 2013-04-28 23:51 -0700
Re: Help creating 'simple' regex "Joey@still_Learning.invalid" <Joey@still_Learning.invalid> - 2013-04-28 09:14 -0700
Re: Help creating 'simple' regex "Joey@still_Learning.invalid" <Joey@still_Learning.invalid> - 2013-04-29 01:40 -0700
csiph-web