Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #39253
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: string function doesn't have array functions |
| Date | 2020-12-07 23:35 +0100 |
| Organization | PointedEars Software (PES) |
| Message-ID | <4278291.LvFx2qVVIh@PointedEars.de> (permalink) |
| References | (1 earlier) <9c34e490-04fd-49a5-8ab5-ff2ba9f0684en@googlegroups.com> <435c57e1-7ae0-4506-8d38-8560bca6f2dan@googlegroups.com> <0fdd8034-346a-420a-acaa-ae832f2a88acn@googlegroups.com> <e0fc4d1f-6294-40c1-81f8-d9753c383a47n@googlegroups.com> <41bac879-f5a8-4099-88ff-f8003fbc1de5n@googlegroups.com> |
Michael Haufe (TNO) wrote:
> If you already have the full string replacing it is straightforward
> enough:
>
> ```
> let cookieData =
> 'SSOD-SAT=AFX1AAAAYABvr;s_cc=true;TLTSID=F4FAF40;XSRF-
^ ^
> TOKEN=D9CF17822CDCA3D8337DE8F4485EA912';
> cookieData = cookieData.replace(/XSRF-TOKEN=(.+)\b/,($0,$1) =>
> `XSRF-TOKEN=000123456`) ```
This replacement will, in general, *obviously* NOT work as expected, as
cookies’ key–value pairs are separated by semicolon, and .+ is greedy.
And there is no need for capturing the old value or for the callback here.
Use .replace(/((?:^|;\s*)XSRF-TOKEN)=[^;]+/, "$1=000123456") instead.
--
PointedEars
FAQ: <http://PointedEars.de/faq> | <http://PointedEars.de/es-matrix>
<https://github.com/PointedEars> | <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
string function doesn't have array functions JRough <janis.rough@gmail.com> - 2020-12-07 07:54 -0800
Re: string function doesn't have array functions Julio Di Egidio <julio@diegidio.name> - 2020-12-07 08:30 -0800
Re: string function doesn't have array functions JRough <janis.rough@gmail.com> - 2020-12-07 09:15 -0800
Re: string function doesn't have array functions "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2020-12-07 10:06 -0800
Re: string function doesn't have array functions JRough <janis.rough@gmail.com> - 2020-12-07 10:28 -0800
Re: string function doesn't have array functions "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2020-12-07 11:33 -0800
Re: string function doesn't have array functions Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2020-12-07 23:35 +0100
Re: string function doesn't have array functions "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2020-12-07 14:36 -0800
Re: string function doesn't have array functions JRough <janis.rough@gmail.com> - 2020-12-07 15:29 -0800
Re: string function doesn't have array functions "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2020-12-07 09:53 -0800
csiph-web