Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #33336
| Newsgroups | comp.lang.javascript |
|---|---|
| Subject | Re: How to perform an EXACT match for an item without looping through? |
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
| References | <5cc88464-96fb-45b6-b2ba-7b5e4f1d9a83@googlegroups.com> <2onjgctpq57a8vqa6i0jp42t58ols8n9rt@4ax.com> <28d725b0-3f1a-4af6-917f-1f8442dd08a6@googlegroups.com> |
| Date | 2017-05-17 19:34 +0200 |
| Message-ID | <XnsA778C7363C1D5eejj99@194.109.6.166> (permalink) |
justaguy <lichunshen84@gmail.com> wrote on 17 May 2017 in
comp.lang.javascript:
> On Wednesday, May 3, 2017 at 9:46:01 AM UTC-4, John G Harris wrote:
>> On Tue, 2 May 2017 18:49:20 -0700 (PDT), justaguy
>> wrote:
>>
>> >
>> >
>> >The following won't work. Is it doable without looping through the
>> >list
> ?
>> >
>> >Thanks.
>> >
>> ><script>
>> > /* find EXACT match of an item from a list without looping
>> > in this case, the 2nd item */
>> >
>> > var list = "2332,123456,9922";
>> >
>> > var f = list.match(/12345/g);
>> >
>> > if (f.length == 0) {
>> > console.log('not found');
>> > }
>> > else {
>> > console.log('found');
>> > }
>> >
>> >
>> > var list = "2332,123456,9922";
>> >
>> > var f = list.indexOf('12345');
>> >
>> > console.log(f);
>> >
>> ></script>
>>
>> Are you able to change the coding, e.g to
>> "|2332|123456|9922|" ?
>> Then looking for "|12345|" won't pick up "|123456|".
>>
>> John
>
> Hmm. There's a bug, that is, if a list item value is not strictly
> numeric data or if alphnumeric then they are also case sensitive
> otherwise such match technique fails. For instance, if we replace
> "12345" with "123AB45", then it won't match "123ab45", I'd like it to be
> case insensitive. Can we still use indexOf ? If so, how?
Did not follow the thread,
but in general change the regex
var f = list.match(/123ab45/g);
to
var f = list.match(/123ab45/ig);
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
How to perform an EXACT match for an item without looping through? justaguy <lichunshen84@gmail.com> - 2017-05-02 18:49 -0700
Re: How to perform an EXACT match for an item without looping through? JJ <jj4public@vfemail.net> - 2017-05-03 18:36 +0700
Re: How to perform an EXACT match for an item without looping through? justaguy <lichunshen84@gmail.com> - 2017-05-03 05:58 -0700
Re: How to perform an EXACT match for an item without looping through? JJ <jj4public@vfemail.net> - 2017-05-04 15:03 +0700
Re: How to perform an EXACT match for an item without looping through? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-05-04 10:57 +0200
Re: How to perform an EXACT match for an item without looping through? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-05-05 18:40 +0200
Re: How to perform an EXACT match for an item without looping through? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-05-05 19:59 +0200
Re: How to perform an EXACT match for an item without looping through? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-05-06 02:10 +0200
Re: How to perform an EXACT match for an item without looping through? John G Harris <niam@jghnorth.org.uk.invalid> - 2017-05-03 14:45 +0100
Re: How to perform an EXACT match for an item without looping through? justaguy <lichunshen84@gmail.com> - 2017-05-03 07:12 -0700
Re: How to perform an EXACT match for an item without looping through? justaguy <lichunshen84@gmail.com> - 2017-05-17 09:58 -0700
Re: How to perform an EXACT match for an item without looping through? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-05-17 19:34 +0200
Re: How to perform an EXACT match for an item without looping through? justaguy <lichunshen84@gmail.com> - 2017-05-17 11:12 -0700
Re: How to perform an EXACT match for an item without looping through? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-05-17 20:33 +0200
Re: How to perform an EXACT match for an item without looping through? justaguy <lichunshen84@gmail.com> - 2017-05-17 15:16 -0700
Re: How to perform an EXACT match for an item without looping through? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-05-18 11:15 +0200
Re: How to perform an EXACT match for an item without looping through? justaguy <lichunshen84@gmail.com> - 2017-05-19 07:58 -0700
csiph-web