Rocksolid Light

Welcome to Rocksolid Light

mail  files  register  newsreader  groups  login

Message-ID:  

Make it myself? But I'm a physical organic chemist!


devel / comp.lang.javascript / Re: trying to match a "word", having difficulty with a "Lookbehind assertion"

SubjectAuthor
* trying to match a "word", having difficulty with a "Lookbehind assertion"R.Wieser
+* Re: trying to match a "word", having difficulty with a "LookbehindThe Natural Philosopher
|`* Re: trying to match a "word", having difficulty with a "Lookbehind assertion"R.Wieser
| `* Re: trying to match a "word", having difficulty with a "LookbehindThe Natural Philosopher
|  `* Re: trying to match a "word", having difficulty with a "Lookbehind assertion"R.Wieser
|   `- Re: trying to match a "word", having difficulty with a "LookbehindThe Natural Philosopher
+* Re: trying to match a "word", having difficulty with a "Lookbehind assertion"JJ
|+- Re: trying to match a "word", having difficulty with a "Lookbehind assertion"R.Wieser
|+* Re: trying to match a "word", having difficulty with a "Lookbehind assertion"Stefan Ram
||`- Re: trying to match a "word", having difficulty with a "Lookbehind assertion"R.Wieser
|`* Re: trying to match a "word", having difficulty with a "Lookbehind assertion"Thomas 'PointedEars' Lahn
| +- Re: trying to match a "word", having difficulty with a "Lookbehind assertion"R.Wieser
| `- Re: trying to match a "word", having difficulty with a "Lookbehind assertion"Thomas 'PointedEars' Lahn
+* Re: trying to match a "word", having difficulty with a "Lookbehind assertion"Scott Sauyet
|`* Re: trying to match a "word", having difficulty with a "Lookbehind assertion"R.Wieser
| `* Re: trying to match a "word", having difficulty with a "Lookbehind assertion"Scott Sauyet
|  `* Re: trying to match a "word", having difficulty with a "Lookbehind assertion"R.Wieser
|   `* Re: trying to match a "word", having difficulty with a "Lookbehind assertion"Scott Sauyet
|    `* Re: trying to match a "word", having difficulty with a "Lookbehind assertion"R.Wieser
|     `* Re: trying to match a "word", having difficulty with a "Lookbehind assertion"Scott Sauyet
|      `* Re: trying to match a "word", having difficulty with a "Lookbehind assertion"R.Wieser
|       `- Re: trying to match a "word", having difficulty with a "Lookbehind assertion"Scott Sauyet
+- Re: trying to match a "word", having difficulty with a "Lookbehind assertion"Кристьян Робам
`- Re: trying to match a "word", having difficulty with a "Lookbehind assertion"Härra Rabmo

1
trying to match a "word", having difficulty with a "Lookbehind assertion"

<t6aath$15hc$1@gioia.aioe.org>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=5227&group=comp.lang.javascript#5227

  copy link   Newsgroups: comp.lang.javascript
Path: i2pn2.org!i2pn.org!aioe.org!XakcSTEO51npqVb7OVl71w.user.46.165.242.75.POSTED!not-for-mail
From: address@not.available (R.Wieser)
Newsgroups: comp.lang.javascript
Subject: trying to match a "word", having difficulty with a "Lookbehind assertion"
Date: Sat, 21 May 2022 11:20:22 +0200
Organization: Aioe.org NNTP Server
Lines: 39
Message-ID: <t6aath$15hc$1@gioia.aioe.org>
Injection-Info: gioia.aioe.org; logging-data="38444"; posting-host="XakcSTEO51npqVb7OVl71w.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
X-MSMail-Priority: Normal
X-RFC2646: Format=Flowed; Original
X-Notice: Filtered by postfilter v. 0.9.2
X-Newsreader: Microsoft Outlook Express 6.00.2900.5512
X-Priority: 3
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5512
 by: R.Wieser - Sat, 21 May 2022 09:20 UTC

Hello all,

I'm trying to match group of characters, delimited by anything that does not
belong in that group.

Case in point: "Couldn't understand a g**d*** word she was saying!"

I would like to match the "g**d***" sequence of letters.

For that I've tried to use a RegEx :

RegExp("(?<=[^a-zA-Z\*])"+escapeRegExp(find)+"(?=[^a-zA-Z\*])",'gi')

-or-

RegExp("(?<![a-zA-Z\*])"+escapeRegExp(find)+"(?=[^a-zA-Z\*])",'gi')

("escapeRegExp()" escapes the "*" to "\*")

The problem is that neither of the above seem to match anything.

When I use the following

RegExp("\ \b"+escapeRegExp(find)+"(?=[^a-zA-Z\*])",'gi')

(no space between the first two slashes. Had to insert it otherwise my
newsclient turns it into a link)

all goes well - but for the problem that than the partial "d***" is matched
before "g**d***", throwing everything off.

Question: if not the above, what /am/ I suppose to use as the "look behind
assertion" ?

Regards,
Rudy Wieser

Re: trying to match a "word", having difficulty with a "Lookbehind assertion"

<t6ae7o$ril$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=5228&group=comp.lang.javascript#5228

  copy link   Newsgroups: comp.lang.javascript
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: tnp@invalid.invalid (The Natural Philosopher)
Newsgroups: comp.lang.javascript
Subject: Re: trying to match a "word", having difficulty with a "Lookbehind
assertion"
Date: Sat, 21 May 2022 11:17:27 +0100
Organization: A little, after lunch
Lines: 50
Message-ID: <t6ae7o$ril$1@dont-email.me>
References: <t6aath$15hc$1@gioia.aioe.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 21 May 2022 10:17:28 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="d3ee91b25158539a2399791722682180";
logging-data="28245"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX180kXjCBi7GQSOvCpnBIZ0Wspj1Gktdirg="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.8.1
Cancel-Lock: sha1:P56f2IRgphfVEcEfyr6+TXSWvFE=
In-Reply-To: <t6aath$15hc$1@gioia.aioe.org>
Content-Language: en-GB
 by: The Natural Philosop - Sat, 21 May 2022 10:17 UTC

On 21/05/2022 10:20, R.Wieser wrote:
> Hello all,
>
> I'm trying to match group of characters, delimited by anything that does not
> belong in that group.
>
> Case in point: "Couldn't understand a g**d*** word she was saying!"
>
> I would like to match the "g**d***" sequence of letters.
>
> For that I've tried to use a RegEx :
>
> RegExp("(?<=[^a-zA-Z\*])"+escapeRegExp(find)+"(?=[^a-zA-Z\*])",'gi')
>
> -or-
>
> RegExp("(?<![a-zA-Z\*])"+escapeRegExp(find)+"(?=[^a-zA-Z\*])",'gi')
>
> ("escapeRegExp()" escapes the "*" to "\*")
>
> The problem is that neither of the above seem to match anything.
>
> When I use the following
>
> RegExp("\ \b"+escapeRegExp(find)+"(?=[^a-zA-Z\*])",'gi')
>
> (no space between the first two slashes. Had to insert it otherwise my
> newsclient turns it into a link)
>
> all goes well - but for the problem that than the partial "d***" is matched
> before "g**d***", throwing everything off.
>
>
> Question: if not the above, what /am/ I suppose to use as the "look behind
> assertion" ?
>
> Regards,
> Rudy Wieser
>
>
In the time you have wasted trying to learn enough regexp, failing, and
posting here, you could have written it in C three times over...

--
“Ideas are inherently conservative. They yield not to the attack of
other ideas but to the massive onslaught of circumstance"

- John K Galbraith

Re: trying to match a "word", having difficulty with a "Lookbehind assertion"

<d4isn07io5cf.h6kqtics0wrc.dlg@40tude.net>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=5229&group=comp.lang.javascript#5229

  copy link   Newsgroups: comp.lang.javascript
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: jj4public@gmx.com (JJ)
Newsgroups: comp.lang.javascript
Subject: Re: trying to match a "word", having difficulty with a "Lookbehind assertion"
Date: Sat, 21 May 2022 19:13:29 +0700
Organization: A noiseless patient Spider
Lines: 49
Message-ID: <d4isn07io5cf.h6kqtics0wrc.dlg@40tude.net>
References: <t6aath$15hc$1@gioia.aioe.org>
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Injection-Info: reader02.eternal-september.org; posting-host="d652280a47bc2963be150faa91648761";
logging-data="6995"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX197TXX720JWFd1Yv8c6l8+rp37swbNda7g="
User-Agent: 40tude_Dialog/2.0.15.84
Cancel-Lock: sha1:NrQulJSJ0F24VXlCgcA/CPHGxZU=
X-Bitcoin: 1LcqwCQBQmhcWfWsVEAeyLchkAY8ZfuMnS
X-Face: \*\`0(1j~VfYC>ebz[&O.]=,Nm\oRM{of,liRO#7Eqi4|!]!(Gs=Akgh{J)605>C9Air?pa d{sSZ09u+A7f<^paR"/NH_#<mE1S"hde\c6PZLUB[t/s5-+Iu5DSc?P0+4%,Hl
 by: JJ - Sat, 21 May 2022 12:13 UTC

On Sat, 21 May 2022 11:20:22 +0200, R.Wieser wrote:
> Hello all,
>
> I'm trying to match group of characters, delimited by anything that does not
> belong in that group.
>
> Case in point: "Couldn't understand a g**d*** word she was saying!"
>
> I would like to match the "g**d***" sequence of letters.
>
> For that I've tried to use a RegEx :
>
> RegExp("(?<=[^a-zA-Z\*])"+escapeRegExp(find)+"(?=[^a-zA-Z\*])",'gi')
>
> -or-
>
> RegExp("(?<![a-zA-Z\*])"+escapeRegExp(find)+"(?=[^a-zA-Z\*])",'gi')
>
> ("escapeRegExp()" escapes the "*" to "\*")
>
> The problem is that neither of the above seem to match anything.
>
> When I use the following
>
> RegExp("\ \b"+escapeRegExp(find)+"(?=[^a-zA-Z\*])",'gi')
>
> (no space between the first two slashes. Had to insert it otherwise my
> newsclient turns it into a link)
>
> all goes well - but for the problem that than the partial "d***" is matched
> before "g**d***", throwing everything off.
>
> Question: if not the above, what /am/ I suppose to use as the "look behind
> assertion" ?
>
> Regards,
> Rudy Wieser

Look-behind is used to match patternA which follows or not follows patternB,
and does not include patternB in the match result.

Your condition is to simply to match "g**d***". You do not have a condition
that, "g**d***" must follow or must not follow other pattern. So,
Look-behind is not needed, or perhaps, not applicable.

For matching just "g**d***" as a whole word, we could just use:
(note: `*` is substituted with `#`)

/\bg##d###\b/gi

Re: trying to match a "word", having difficulty with a "Lookbehind assertion"

<t6at8v$hi9$1@gioia.aioe.org>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=5230&group=comp.lang.javascript#5230

  copy link   Newsgroups: comp.lang.javascript
Path: i2pn2.org!rocksolid2!i2pn.org!news.niel.me!aioe.org!XakcSTEO51npqVb7OVl71w.user.46.165.242.75.POSTED!not-for-mail
From: address@not.available (R.Wieser)
Newsgroups: comp.lang.javascript
Subject: Re: trying to match a "word", having difficulty with a "Lookbehind assertion"
Date: Sat, 21 May 2022 16:33:51 +0200
Organization: Aioe.org NNTP Server
Lines: 48
Message-ID: <t6at8v$hi9$1@gioia.aioe.org>
References: <t6aath$15hc$1@gioia.aioe.org> <d4isn07io5cf.h6kqtics0wrc.dlg@40tude.net>
Injection-Info: gioia.aioe.org; logging-data="17993"; posting-host="XakcSTEO51npqVb7OVl71w.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
X-RFC2646: Format=Flowed; Original
X-Priority: 3
X-Newsreader: Microsoft Outlook Express 6.00.2900.5512
X-MSMail-Priority: Normal
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5512
X-Notice: Filtered by postfilter v. 0.9.2
 by: R.Wieser - Sat, 21 May 2022 14:33 UTC

JJ,

> Look-behind is used to match patternA which follows or not follows
> patternB, and does not include patternB in the match result.

Yeah, I read that too :

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Assertions

> Your condition is to simply to match "g**d***". You do not have a
> condition
> that, "g**d***" must follow or must not follow other pattern.

Whut ? What do you think my 'RegExp(...)' is about than ?

Maybe a bit more code will help :

'- - - - - - - - - - - - - - - - - -

function escapeRegExp(string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the
whole matched string
}

function replaceAll(str, find, replace) {
return str.replace(new RegExp("(?<=[^a-zA-Z\*])" + escapeRegExp(find) +
"(?=[^a-zA-Z\*])",'gi'), replace);;
}

newString = oldString.replaceAll("g**d***","goddamn")

'- - - - - - - - - - - - - - - - - -

My own contribution to the above are just the "(?....)" parts. The latter
one works, the former doesn't.

But, I think I found why it doesn't work : I just found out that my FF v52
already throws an "invalid regexp group" error on something simple as
oldString.replace(/(?<=p)a/g, "!");

No idea why though - and thus no idea what to replace it with either.

Regards,
Rudy Wieser

Re: trying to match a "word", having difficulty with a "Lookbehind assertion"

<generalization-20220521170814@ram.dialup.fu-berlin.de>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=5231&group=comp.lang.javascript#5231

  copy link   Newsgroups: comp.lang.javascript
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.javascript
Subject: Re: trying to match a "word", having difficulty with a "Lookbehind assertion"
Date: 21 May 2022 16:08:32 GMT
Organization: Stefan Ram
Lines: 13
Expires: 1 Apr 2023 11:59:58 GMT
Message-ID: <generalization-20220521170814@ram.dialup.fu-berlin.de>
References: <t6aath$15hc$1@gioia.aioe.org> <d4isn07io5cf.h6kqtics0wrc.dlg@40tude.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de GLa88+rml1+sfhssIIL+mQSxhWDZGOSVV7Kzr5xqKXPR+Y
X-Copyright: (C) Copyright 2022 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
Accept-Language: de-DE, en-US, it, fr-FR
 by: Stefan Ram - Sat, 21 May 2022 16:08 UTC

JJ <jj4public@gmx.com> writes:
>For matching just

Probably the OP needs some generalization, but only he knows
which generalization exactly. For one example, on the console,

|>|"alpha beta g****d*** eps".replace( /.*?\b([\w*]*\*[\w*]).*/, '$1' )
| |
|<|"g****d***"

.

Re: trying to match a "word", having difficulty with a "Lookbehind assertion"

<t6b8ge$18qd$1@gioia.aioe.org>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=5232&group=comp.lang.javascript#5232

  copy link   Newsgroups: comp.lang.javascript
Path: i2pn2.org!i2pn.org!aioe.org!XakcSTEO51npqVb7OVl71w.user.46.165.242.75.POSTED!not-for-mail
From: address@not.available (R.Wieser)
Newsgroups: comp.lang.javascript
Subject: Re: trying to match a "word", having difficulty with a "Lookbehind assertion"
Date: Sat, 21 May 2022 19:45:35 +0200
Organization: Aioe.org NNTP Server
Lines: 13
Message-ID: <t6b8ge$18qd$1@gioia.aioe.org>
References: <t6aath$15hc$1@gioia.aioe.org> <d4isn07io5cf.h6kqtics0wrc.dlg@40tude.net> <generalization-20220521170814@ram.dialup.fu-berlin.de>
Injection-Info: gioia.aioe.org; logging-data="41805"; posting-host="XakcSTEO51npqVb7OVl71w.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
X-Notice: Filtered by postfilter v. 0.9.2
X-RFC2646: Format=Flowed; Original
X-Priority: 3
X-MSMail-Priority: Normal
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5512
X-Newsreader: Microsoft Outlook Express 6.00.2900.5512
 by: R.Wieser - Sat, 21 May 2022 17:45 UTC

Stefan,

> |>|"alpha beta g****d*** eps".replace( /.*?\b([\w*]*\*[\w*]).*/, '$1' )
> | |
> |<|"g****d***"

The ultimate idea is to replace the sought-for word. Throwing away
everything thats "not it" isn't a viable approach I'm afraid.

Regards,
Rudy Wieser

Re: trying to match a "word", having difficulty with a "Lookbehind assertion"

<t6d7je$48r$1@gioia.aioe.org>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=5234&group=comp.lang.javascript#5234

  copy link   Newsgroups: comp.lang.javascript
Path: i2pn2.org!i2pn.org!aioe.org!XakcSTEO51npqVb7OVl71w.user.46.165.242.75.POSTED!not-for-mail
From: address@not.available (R.Wieser)
Newsgroups: comp.lang.javascript
Subject: Re: trying to match a "word", having difficulty with a "Lookbehind assertion"
Date: Sun, 22 May 2022 13:42:31 +0200
Organization: Aioe.org NNTP Server
Lines: 14
Message-ID: <t6d7je$48r$1@gioia.aioe.org>
References: <t6aath$15hc$1@gioia.aioe.org> <t6ae7o$ril$1@dont-email.me>
Injection-Info: gioia.aioe.org; logging-data="4379"; posting-host="XakcSTEO51npqVb7OVl71w.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
X-MSMail-Priority: Normal
X-Notice: Filtered by postfilter v. 0.9.2
X-RFC2646: Format=Flowed; Response
X-Newsreader: Microsoft Outlook Express 6.00.2900.5512
X-Priority: 3
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5512
 by: R.Wieser - Sun, 22 May 2022 11:42 UTC

TNP,

> In the time you have wasted trying to learn enough regexp, failing, and
> posting here, you could have written it in C three times over...

Good idea ! Now all you have to tell me how I get that C code loaded and
running in a browsers webpage ...

.... Idiot.

Regards,
Rudy Wieser

Re: trying to match a "word", having difficulty with a "Lookbehind assertion"

<t6d8q8$cb9$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=5235&group=comp.lang.javascript#5235

  copy link   Newsgroups: comp.lang.javascript
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: tnp@invalid.invalid (The Natural Philosopher)
Newsgroups: comp.lang.javascript
Subject: Re: trying to match a "word", having difficulty with a "Lookbehind
assertion"
Date: Sun, 22 May 2022 13:03:20 +0100
Organization: A little, after lunch
Lines: 27
Message-ID: <t6d8q8$cb9$1@dont-email.me>
References: <t6aath$15hc$1@gioia.aioe.org> <t6ae7o$ril$1@dont-email.me>
<t6d7je$48r$1@gioia.aioe.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 22 May 2022 12:03:20 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="f8ab4089c687b8e805df08c743b6878c";
logging-data="12649"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/JNZ/bxml4QniracwKLQwRcpp4HuXJhT8="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.9.1
Cancel-Lock: sha1:O8uXmHraghugT6aIEILEcWl5PYI=
In-Reply-To: <t6d7je$48r$1@gioia.aioe.org>
Content-Language: en-GB
 by: The Natural Philosop - Sun, 22 May 2022 12:03 UTC

On 22/05/2022 12:42, R.Wieser wrote:
> TNP,
>
>> In the time you have wasted trying to learn enough regexp, failing, and
>> posting here, you could have written it in C three times over...
>
> Good idea ! Now all you have to tell me how I get that C code loaded and
> running in a browsers webpage ...

Google cgi-bin and AJAX

>
> ... Idiot.
>
Well javascript then. Its similar.

> Regards,
> Rudy Wieser
>
>

--
“But what a weak barrier is truth when it stands in the way of an
hypothesis!”

Mary Wollstonecraft

Re: trying to match a "word", having difficulty with a "Lookbehind assertion"

<t6dlku$1vr6$1@gioia.aioe.org>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=5236&group=comp.lang.javascript#5236

  copy link   Newsgroups: comp.lang.javascript
Path: i2pn2.org!i2pn.org!aioe.org!XakcSTEO51npqVb7OVl71w.user.46.165.242.75.POSTED!not-for-mail
From: address@not.available (R.Wieser)
Newsgroups: comp.lang.javascript
Subject: Re: trying to match a "word", having difficulty with a "Lookbehind assertion"
Date: Sun, 22 May 2022 17:42:18 +0200
Organization: Aioe.org NNTP Server
Lines: 30
Message-ID: <t6dlku$1vr6$1@gioia.aioe.org>
References: <t6aath$15hc$1@gioia.aioe.org> <t6ae7o$ril$1@dont-email.me> <t6d7je$48r$1@gioia.aioe.org> <t6d8q8$cb9$1@dont-email.me>
Injection-Info: gioia.aioe.org; logging-data="65382"; posting-host="XakcSTEO51npqVb7OVl71w.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
X-Newsreader: Microsoft Outlook Express 6.00.2900.5512
X-Notice: Filtered by postfilter v. 0.9.2
X-RFC2646: Format=Flowed; Response
X-MSMail-Priority: Normal
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5512
X-Priority: 3
 by: R.Wieser - Sun, 22 May 2022 15:42 UTC

TNP,

> Google cgi-bin and AJAX

Good idea ! Now a simple, locally run JS command is translated to
something *way* heavier and complex, needing to communicate with a server
and going over two different frameworks to do the work . Oh wait, three
including the actual search-and-replace program.

I can see it now : the server sends a full webpage to the browser, than the
browser extracts all textparts from it one by one, sends each of them back
to the server and asks it to do a search-and-replace, after which the server
sends that part back and have Ajax replace the involved textpart in the
browser. Rinse and repeat for a list of to be replaced words. One
webpage, going around at least trice.

Nahhh, I don't think so. It would be *much* simpler to just send the whole
list of words and than have the server do everything at once and send the
full updated webpage back. Using PHP for the search-and-replace ofcourse.

.... if the JS I posted would be coming from the/a server to begin with.
Which it doesn't. IOW, the above doesn't even apply.

Besides, JS itself is good a enough language to create a non-regexp solution
in.

Regards,
Rudy Wieser

Re: trying to match a "word", having difficulty with a "Lookbehind assertion"

<t6g0c6$uut$3@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=5237&group=comp.lang.javascript#5237

  copy link   Newsgroups: comp.lang.javascript
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: tnp@invalid.invalid (The Natural Philosopher)
Newsgroups: comp.lang.javascript
Subject: Re: trying to match a "word", having difficulty with a "Lookbehind
assertion"
Date: Mon, 23 May 2022 13:57:42 +0100
Organization: A little, after lunch
Lines: 43
Message-ID: <t6g0c6$uut$3@dont-email.me>
References: <t6aath$15hc$1@gioia.aioe.org> <t6ae7o$ril$1@dont-email.me>
<t6d7je$48r$1@gioia.aioe.org> <t6d8q8$cb9$1@dont-email.me>
<t6dlku$1vr6$1@gioia.aioe.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 23 May 2022 12:57:42 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="b5a575a277ca07be2375dcf564f3f3d2";
logging-data="31709"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/gZkBEhTQtMp68cnSjmzhh8Dp0wohHPQU="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.9.1
Cancel-Lock: sha1:iW9dB3OFJut/Rz8uFQgEY4BskcQ=
In-Reply-To: <t6dlku$1vr6$1@gioia.aioe.org>
Content-Language: en-GB
 by: The Natural Philosop - Mon, 23 May 2022 12:57 UTC

On 22/05/2022 16:42, R.Wieser wrote:
> TNP,
>
>> Google cgi-bin and AJAX
>
> Good idea ! Now a simple, locally run JS command is translated to
> something *way* heavier and complex, needing to communicate with a server
> and going over two different frameworks to do the work . Oh wait, three
> including the actual search-and-replace program.
>
I never said it would be lightweight or ideal. Merely that it was possible.
Neither are regexps.

> I can see it now : the server sends a full webpage to the browser, than the
> browser extracts all textparts from it one by one, sends each of them back
> to the server and asks it to do a search-and-replace, after which the server
> sends that part back and have Ajax replace the involved textpart in the
> browser. Rinse and repeat for a list of to be replaced words. One
> webpage, going around at least trice.
>
> Nahhh, I don't think so. It would be *much* simpler to just send the whole
> list of words and than have the server do everything at once and send the
> full updated webpage back. Using PHP for the search-and-replace ofcourse.
>
> ... if the JS I posted would be coming from the/a server to begin with.
> Which it doesn't. IOW, the above doesn't even apply.
>
> Besides, JS itself is good a enough language to create a non-regexp solution
> in.
>

As I said.

> Regards,
> Rudy Wieser
>
>

--
In a Time of Universal Deceit, Telling the Truth Is a Revolutionary Act.

- George Orwell

Re: trying to match a "word", having difficulty with a "Lookbehind assertion"

<2652883.mvXUDI8C0e@PointedEars.de>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=5254&group=comp.lang.javascript#5254

  copy link   Newsgroups: comp.lang.javascript
Path: i2pn2.org!i2pn.org!aioe.org!news.mb-net.net!open-news-network.org!.POSTED.178.197.204.129!not-for-mail
From: PointedEars@web.de (Thomas 'PointedEars' Lahn)
Newsgroups: comp.lang.javascript
Subject: Re: trying to match a "word", having difficulty with a "Lookbehind assertion"
Date: Thu, 09 Jun 2022 00:14:52 +0200
Organization: PointedEars Software (PES)
Lines: 28
Message-ID: <2652883.mvXUDI8C0e@PointedEars.de>
References: <t6aath$15hc$1@gioia.aioe.org> <d4isn07io5cf.h6kqtics0wrc.dlg@40tude.net>
Reply-To: Thomas 'PointedEars' Lahn <usenet@PointedEars.de>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 8Bit
Injection-Info: gwaiyur.mb-net.net; posting-host="178.197.204.129";
logging-data="1624414"; mail-complaints-to="abuse@open-news-network.org"
User-Agent: KNode/4.14.10
Cancel-Lock: sha1:KIOtHhOKEHn0ztsNxdUlt3vLIqA=
X-User-ID: U2FsdGVkX18D1o6ed4OpnQHHITD7UySd23YM57UWetaY0fWJ3k/GRg==
Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEXTxa4RFk5dUWANED8PFEfy7+MGBiW+n3ZNF/QuAAACaElEQVQ4jVXUwVOcMBQG8Dc7Rc4PUntdWV2uxjDpGaGeozOp1woar4jd5t/v9wLstMwsA/ntlxdCAgUc1hjTc9/JCZfGoo3wG3HdmdAWrIJRHe7GM/TmpY5VFefuVcAkkPbLIaN8rmPmjloyZxgyR3GuJ4K0AGtJ2htz8o7yqikm759fldQXaMpbDzjKAG+8v+AugVTOPO5DOjLvGtUYQwh0CPjnVMyGd+8/GfUB5nLKJDD2aLDh5HYyMDJGDwQIo2ZmZcKbowNmAdB/AzyFhrmF2MHRb0QJJfaAnwGB6orZhoykLzJtGwF/xpYxI1dswomiUj3gTuAIqCn/4C7cULwGNBtwMTk3Y4LfKB5YUaOKBKYtpplm7u0vip8tU1NWWyI/7XdcSuIDoMt6rVHMWT0DbjHPGqDqZVSa6zleLcUTcIKLoMv3ueJluALtAo9B302zPPlrtiVScRdCjXvVh3e3JpYa/jjkuC9N+LrBMlz/eAN4eQijX2EdLo6c5tGGHwLyHFtXk89dDGHwCVhG9T0S/j55AhRZgkMCmUQXJ49TnS1wnQDvw0eAh9ICeMmEFbCnPMFzjAvsWoEWEFdYEx+S0MoUZ1gT1wId8+AF3Bl2OoEu906AUHx5VLw/gXYg/x84loOah/2UYNrgiwSwGO7RfUzVBbx/kgpckumGOi6QirtD6gkLTitbnxNol47S2jVc2vsN5kPqaAHT8uUdAJM4v/DanjYOwmUjWznGfwB7sGtAtor5BgofDuzaRj4kSQAqDakTsKORa3Q3xKi3gE1fhl71KRMqrdZ2AWNNg/YOhQyrVBnb+i+nEg4bsDA+egAAAABJRU5ErkJggg==
X-Face: %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&.<b';Md8`dH6iqhT)6C^.Px|[=M@7=Ik[_w<%n1Up"LPQNu2m8|L!/3iby{-]A+#YE}Kl{Cw$\U!kD%K}\2jz"QQP6Uqr],./"?;=4v
 by: Thomas 'Pointed - Wed, 8 Jun 2022 22:14 UTC

JJ wrote:

> On Sat, 21 May 2022 11:20:22 +0200, R.Wieser wrote:
>> For that I've tried to use a RegEx :
>>
>> RegExp("(?<=[^a-zA-Z\*])"+escapeRegExp(find)+"(?=[^a-zA-Z\*])",'gi')

There is a conceptual problem in this line near the beginning and the end…

>> -or-
>>
>> RegExp("(?<![a-zA-Z\*])"+escapeRegExp(find)+"(?=[^a-zA-Z\*])",'gi')

…and in this line near the beginning and the end.

The same problem leads to a program logic problem (although not a syntax
error, which is why it is not so easily spotted) in the following line:

> RegExp("\ \b"+escapeRegExp(find)+"(?=[^a-zA-Z\*])",'gi')

It is too bad that the OP was posting with an invalid “From” header field
via a troll server, so that is all that I will say about it until at least
the former changes. Then again, they may have found the problem already.

--
PointedEars
<https://github.com/PointedEars> | <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2
Please do not cc me. /Bitte keine Kopien per E-Mail.

Re: trying to match a "word", having difficulty with a "Lookbehind assertion"

<t7s6og$1cpk$1@gioia.aioe.org>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=5255&group=comp.lang.javascript#5255

  copy link   Newsgroups: comp.lang.javascript
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!aioe.org!XakcSTEO51npqVb7OVl71w.user.46.165.242.75.POSTED!not-for-mail
From: address@not.available (R.Wieser)
Newsgroups: comp.lang.javascript
Subject: Re: trying to match a "word", having difficulty with a "Lookbehind assertion"
Date: Thu, 9 Jun 2022 09:16:06 +0200
Organization: Aioe.org NNTP Server
Lines: 25
Message-ID: <t7s6og$1cpk$1@gioia.aioe.org>
References: <t6aath$15hc$1@gioia.aioe.org> <d4isn07io5cf.h6kqtics0wrc.dlg@40tude.net> <2652883.mvXUDI8C0e@PointedEars.de>
Injection-Info: gioia.aioe.org; logging-data="45876"; posting-host="XakcSTEO51npqVb7OVl71w.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.5512
X-Notice: Filtered by postfilter v. 0.9.2
X-Priority: 3
X-RFC2646: Format=Flowed; Original
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5512
 by: R.Wieser - Thu, 9 Jun 2022 07:16 UTC

Thomas,

>>> RegExp("(?<=[^a-zA-Z\*])"+escapeRegExp(find)+"(?=[^a-zA-Z\*])",'gi')
>
> There is a conceptual problem in this line near the beginning and the end.

You may want to explain that. And no, I'm not going to either guess or try
to read your mind for what you might be meaning.

> The same problem leads to a program logic problem (although not a syntax
> error, which is why it is not so easily spotted) in the following line:

You've now made two claims of of which you didn't prove, underbuild or even
explained either. How is that in any way helpfull ?

You've also not posted not anything that might actually help me find any
kind of solution.

tl;dr:
your current post is as helpfull as a bit of lorem ipsum.

Regards,
Rudy Wieser

Re: trying to match a "word", having difficulty with a "Lookbehind assertion"

<1986577.oMNUckLgyt@PointedEars.de>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=5256&group=comp.lang.javascript#5256

  copy link   Newsgroups: comp.lang.javascript
Path: i2pn2.org!i2pn.org!aioe.org!news.mb-net.net!open-news-network.org!.POSTED.178.197.204.129!not-for-mail
From: PointedEars@web.de (Thomas 'PointedEars' Lahn)
Newsgroups: comp.lang.javascript
Subject: Re: trying to match a "word", having difficulty with a "Lookbehind assertion"
Date: Thu, 09 Jun 2022 12:21:01 +0200
Organization: PointedEars Software (PES)
Lines: 17
Message-ID: <1986577.oMNUckLgyt@PointedEars.de>
References: <t6aath$15hc$1@gioia.aioe.org> <d4isn07io5cf.h6kqtics0wrc.dlg@40tude.net> <2652883.mvXUDI8C0e@PointedEars.de>
Reply-To: Thomas 'PointedEars' Lahn <usenet@PointedEars.de>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 8Bit
Injection-Info: gwaiyur.mb-net.net; posting-host="178.197.204.129";
logging-data="1827444"; mail-complaints-to="abuse@open-news-network.org"
User-Agent: KNode/4.14.10
Cancel-Lock: sha1:ipQOTJCmQ1iZO+Zn1BvWPmDJhSc=
X-Face: %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&.<b';Md8`dH6iqhT)6C^.Px|[=M@7=Ik[_w<%n1Up"LPQNu2m8|L!/3iby{-]A+#YE}Kl{Cw$\U!kD%K}\2jz"QQP6Uqr],./"?;=4v
Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEXTxa4RFk5dUWANED8PFEfy7+MGBiW+n3ZNF/QuAAACaElEQVQ4jVXUwVOcMBQG8Dc7Rc4PUntdWV2uxjDpGaGeozOp1woar4jd5t/v9wLstMwsA/ntlxdCAgUc1hjTc9/JCZfGoo3wG3HdmdAWrIJRHe7GM/TmpY5VFefuVcAkkPbLIaN8rmPmjloyZxgyR3GuJ4K0AGtJ2htz8o7yqikm759fldQXaMpbDzjKAG+8v+AugVTOPO5DOjLvGtUYQwh0CPjnVMyGd+8/GfUB5nLKJDD2aLDh5HYyMDJGDwQIo2ZmZcKbowNmAdB/AzyFhrmF2MHRb0QJJfaAnwGB6orZhoykLzJtGwF/xpYxI1dswomiUj3gTuAIqCn/4C7cULwGNBtwMTk3Y4LfKB5YUaOKBKYtpplm7u0vip8tU1NWWyI/7XdcSuIDoMt6rVHMWT0DbjHPGqDqZVSa6zleLcUTcIKLoMv3ueJluALtAo9B302zPPlrtiVScRdCjXvVh3e3JpYa/jjkuC9N+LrBMlz/eAN4eQijX2EdLo6c5tGGHwLyHFtXk89dDGHwCVhG9T0S/j55AhRZgkMCmUQXJ49TnS1wnQDvw0eAh9ICeMmEFbCnPMFzjAvsWoEWEFdYEx+S0MoUZ1gT1wId8+AF3Bl2OoEu906AUHx5VLw/gXYg/x84loOah/2UYNrgiwSwGO7RfUzVBbx/kgpckumGOi6QirtD6gkLTitbnxNol47S2jVc2vsN5kPqaAHT8uUdAJM4v/DanjYOwmUjWznGfwB7sGtAtor5BgofDuzaRj4kSQAqDakTsKORa3Q3xKi3gE1fhl71KRMqrdZ2AWNNg/YOhQyrVBnb+i+nEg4bsDA+egAAAABJRU5ErkJggg==
X-User-ID: U2FsdGVkX1/9eoSIbvSx/vJsnqJGHR375mcQxUNlQiQA2UXGjhkXFA==
 by: Thomas 'Pointed - Thu, 9 Jun 2022 10:21 UTC

Thomas 'PointedEars' Lahn wrote:

> JJ wrote:
>> On Sat, 21 May 2022 11:20:22 +0200, R.Wieser wrote:
>
> […]
> The same problem leads to a program logic problem (although not a syntax
> error, which is why it is not so easily spotted) in the following line:
>
>> RegExp("\ \b"+escapeRegExp(find)+"(?=[^a-zA-Z\*])",'gi')

Sorry for the wrong quotation level, it should have been two “>” originally.

--
PointedEars
<https://github.com/PointedEars> | <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2
Please do not cc me. /Bitte keine Kopien per E-Mail.

Re: trying to match a "word", having difficulty with a "Lookbehind assertion"

<628b4693-e733-4d3d-bd00-8ab522e92262n@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=5257&group=comp.lang.javascript#5257

  copy link   Newsgroups: comp.lang.javascript
X-Received: by 2002:a05:620a:6006:b0:6a6:c005:7c14 with SMTP id dw6-20020a05620a600600b006a6c0057c14mr4908002qkb.691.1655229410051;
Tue, 14 Jun 2022 10:56:50 -0700 (PDT)
X-Received: by 2002:a05:6870:912a:b0:fe:1981:b15a with SMTP id
o42-20020a056870912a00b000fe1981b15amr3245731oae.77.1655229409773; Tue, 14
Jun 2022 10:56:49 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.javascript
Date: Tue, 14 Jun 2022 10:56:49 -0700 (PDT)
In-Reply-To: <t6aath$15hc$1@gioia.aioe.org>
Injection-Info: google-groups.googlegroups.com; posting-host=170.202.22.116; posting-account=jEz2WAoAAABPN6KvjkIr_ZIYJY4YFml9
NNTP-Posting-Host: 170.202.22.116
References: <t6aath$15hc$1@gioia.aioe.org>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <628b4693-e733-4d3d-bd00-8ab522e92262n@googlegroups.com>
Subject: Re: trying to match a "word", having difficulty with a "Lookbehind assertion"
From: scott@sauyet.com (Scott Sauyet)
Injection-Date: Tue, 14 Jun 2022 17:56:50 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 2470
 by: Scott Sauyet - Tue, 14 Jun 2022 17:56 UTC

R.Wieser wrote:
> I'm trying to match group of characters, delimited by anything that does not
> belong in that group.
>
> Case in point: "Couldn't understand a g**d*** word she was saying!"
>
> I would like to match the "g**d***" sequence of letters.

I don't understand your look-behind discussion at all. If all you want
to do is to replace some string in another, it's mostly a
simple problem, with the only significant complexity coming from needing
to escape certain characters for a regular expression.

This should work:

```
const replaceTerm = (term, replacement) => (text) =>
text .replace (new RegExp (term.replace(/\*/g, "\\*"), "gi"), replacement)

replaceTerm
("g**d***", "🔵🟡🔴🟢🔵🟡")
("Couldn't understand a g**d*** word she was saying!")
//=> "Couldn't understand a 🔵🟡🔴🟢🔵🟡 word she was saying!"
```

Obviously, you can do whatever sophisticated escape replacement you need
on the term before passing it to the RegExp constructor.

I'm guessing that the point Thomas was trying to be mysterious about is
the lack of a `new` when you created the RexExp.

-- Scott

Re: trying to match a "word", having difficulty with a "Lookbehind assertion"

<t8c2q9$p06$1@gioia.aioe.org>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=5258&group=comp.lang.javascript#5258

  copy link   Newsgroups: comp.lang.javascript
Path: i2pn2.org!i2pn.org!aioe.org!XakcSTEO51npqVb7OVl71w.user.46.165.242.75.POSTED!not-for-mail
From: address@not.available (R.Wieser)
Newsgroups: comp.lang.javascript
Subject: Re: trying to match a "word", having difficulty with a "Lookbehind assertion"
Date: Wed, 15 Jun 2022 09:47:12 +0200
Organization: Aioe.org NNTP Server
Lines: 29
Message-ID: <t8c2q9$p06$1@gioia.aioe.org>
References: <t6aath$15hc$1@gioia.aioe.org> <628b4693-e733-4d3d-bd00-8ab522e92262n@googlegroups.com>
Injection-Info: gioia.aioe.org; logging-data="25606"; posting-host="XakcSTEO51npqVb7OVl71w.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
X-Newsreader: Microsoft Outlook Express 6.00.2900.5512
X-Priority: 3
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5512
X-RFC2646: Format=Flowed; Original
X-Notice: Filtered by postfilter v. 0.9.2
X-MSMail-Priority: Normal
 by: R.Wieser - Wed, 15 Jun 2022 07:47 UTC

Scott,

> I don't understand your look-behind discussion at all. If all you
> want to do is to replace some string in another, it's mostly a
> simple problem, with the only significant complexity coming from
> needing to escape certain characters for a regular expression.

Google "clbuttic mistake" and you'll know what the problem with that is.
:-)

> ("g**d***", "????????????")
> ("Couldn't understand a g**d*** word she was saying!")

Now imagine that ("d***", "damn") is another replacement, which might be
executed before the ("g**d***", "goddamn") one. I would be left with
"g**damn". Not good.

Or "p****" -> "pussy" and "p*****" -> "pissed" (a single "*" difference).
If replaced in that order what /should/ result in "pissed" would become
"pussy*" instead. Also not good.

By the way : I got my "check for delimitation" idea from the (build in) "\b"
check (ask yourself: why does it exist ?). It doesn't quite work for what
I need it for, so I tried to roll my own. And failed. :-(

Regards
Rudy Wieser

Re: trying to match a "word", having difficulty with a "Lookbehind assertion"

<5844f300-546d-48a5-884f-f10c2078b084n@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=5259&group=comp.lang.javascript#5259

  copy link   Newsgroups: comp.lang.javascript
X-Received: by 2002:a05:600c:501f:b0:39d:a3d:e919 with SMTP id n31-20020a05600c501f00b0039d0a3de919mr1103868wmr.132.1655322158018;
Wed, 15 Jun 2022 12:42:38 -0700 (PDT)
X-Received: by 2002:a05:6870:1790:b0:101:3509:5f58 with SMTP id
r16-20020a056870179000b0010135095f58mr761831oae.148.1655322157367; Wed, 15
Jun 2022 12:42:37 -0700 (PDT)
Path: i2pn2.org!i2pn.org!aioe.org!news.uzoreto.com!feeder1.cambriumusenet.nl!feed.tweak.nl!209.85.128.88.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.javascript
Date: Wed, 15 Jun 2022 12:42:37 -0700 (PDT)
In-Reply-To: <t8c2q9$p06$1@gioia.aioe.org>
Injection-Info: google-groups.googlegroups.com; posting-host=170.202.22.116; posting-account=jEz2WAoAAABPN6KvjkIr_ZIYJY4YFml9
NNTP-Posting-Host: 170.202.22.116
References: <t6aath$15hc$1@gioia.aioe.org> <628b4693-e733-4d3d-bd00-8ab522e92262n@googlegroups.com>
<t8c2q9$p06$1@gioia.aioe.org>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <5844f300-546d-48a5-884f-f10c2078b084n@googlegroups.com>
Subject: Re: trying to match a "word", having difficulty with a "Lookbehind assertion"
From: scott@sauyet.com (Scott Sauyet)
Injection-Date: Wed, 15 Jun 2022 19:42:37 +0000
Content-Type: text/plain; charset="UTF-8"
 by: Scott Sauyet - Wed, 15 Jun 2022 19:42 UTC

R.Wieser wrote:
> Scott Sauyet wrote:

>> I don't understand your look-behind discussion at all. If all you
>> want to do is to replace some string in another, it's mostly a
>> simple problem, with the only significant complexity coming from
>> needing to escape certain characters for a regular expression.

> Google "clbuttic mistake" and you'll know what the problem with that is.
> :-)

Oh, I understand that problem. Which is what worries me with ever
trying to do what you seem to be trying to do.

>> ("g**d***", "????????????")
>> ("Couldn't understand a g**d*** word she was saying!")

> Now imagine that ("d***", "damn") is another replacement, which might be
> executed before the ("g**d***", "goddamn") one. I would be left with
> "g**damn". Not good.

Ahh, so this isn't about replacing the regex at all, but how to organize
a collection of search strings. Is that right? Because if that is, then
we simply need to define a partial ordering of the search strings and do
a topological sort of the resulting dependency graph, in order to run the
replacements one-by-one. Does that sound correct?

If that's what you're looking for, then this might define a useful partial
ordering:

```
const useBefore = (s, t) => new RegExp (t .replace (/\*/g, '.')) .test (s)

useBefore ('d***', 'g**d****') //=> false
useBefore ('g**d****', 'd***') //=> true
useBefore ('d**n', 'd***') //=> true
useBefore ('d***', 'd**n') //=> false
useBefore ('abc', 'xyz') //=> false
useBefore ('xyz', 'abc') //=> false
```

Note that the last two examples show that this is only a partial ordering.

If this is what you need, then the next step is simply to apply a
topological sort [1] of the graph generated by that partial order. There
are well-known algorithms for this.

[1]: https://en.wikipedia.org/wiki/Topological_sorting

-- Scott

Re: trying to match a "word", having difficulty with a "Lookbehind assertion"

<t8dekk$egm$1@gioia.aioe.org>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=5260&group=comp.lang.javascript#5260

  copy link   Newsgroups: comp.lang.javascript
Path: i2pn2.org!i2pn.org!aioe.org!XakcSTEO51npqVb7OVl71w.user.46.165.242.75.POSTED!not-for-mail
From: address@not.available (R.Wieser)
Newsgroups: comp.lang.javascript
Subject: Re: trying to match a "word", having difficulty with a "Lookbehind assertion"
Date: Wed, 15 Jun 2022 22:15:11 +0200
Organization: Aioe.org NNTP Server
Lines: 20
Message-ID: <t8dekk$egm$1@gioia.aioe.org>
References: <t6aath$15hc$1@gioia.aioe.org> <628b4693-e733-4d3d-bd00-8ab522e92262n@googlegroups.com> <t8c2q9$p06$1@gioia.aioe.org> <5844f300-546d-48a5-884f-f10c2078b084n@googlegroups.com>
Injection-Info: gioia.aioe.org; logging-data="14870"; posting-host="XakcSTEO51npqVb7OVl71w.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
X-Notice: Filtered by postfilter v. 0.9.2
X-RFC2646: Format=Flowed; Original
X-Newsreader: Microsoft Outlook Express 6.00.2900.5512
X-Priority: 3
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5512
X-MSMail-Priority: Normal
 by: R.Wieser - Wed, 15 Jun 2022 20:15 UTC

Scott,

> Ahh, so this isn't about replacing the regex at all, but how to
> organize a collection of search strings. Is that right?

Nope. It really is about creating a regexp that matches searchstrings as
if they are words.

I know I can sort the searchstrings and solve my problem that way, but that
currently is not my interest. Thank you for that "topological sorting"
link though.

Imagine that I have "g**d***" somewhere in the text, but no replacement for
it yet. But I already have "d***" as a searchstring. In that case that
"g**d***" should stay as it is.

Regards,
Rudy Wieser

Re: trying to match a "word", having difficulty with a "Lookbehind assertion"

<0ac3789b-098e-4787-96c2-c5dd07b7629dn@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=5261&group=comp.lang.javascript#5261

  copy link   Newsgroups: comp.lang.javascript
X-Received: by 2002:a05:600c:a02:b0:39c:97cc:82e3 with SMTP id z2-20020a05600c0a0200b0039c97cc82e3mr11989140wmp.97.1655325151292;
Wed, 15 Jun 2022 13:32:31 -0700 (PDT)
X-Received: by 2002:a05:6870:2053:b0:ec:d66d:d9d0 with SMTP id
l19-20020a056870205300b000ecd66dd9d0mr802841oad.196.1655325150639; Wed, 15
Jun 2022 13:32:30 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.128.87.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.javascript
Date: Wed, 15 Jun 2022 13:32:30 -0700 (PDT)
In-Reply-To: <t8dekk$egm$1@gioia.aioe.org>
Injection-Info: google-groups.googlegroups.com; posting-host=170.202.22.116; posting-account=jEz2WAoAAABPN6KvjkIr_ZIYJY4YFml9
NNTP-Posting-Host: 170.202.22.116
References: <t6aath$15hc$1@gioia.aioe.org> <628b4693-e733-4d3d-bd00-8ab522e92262n@googlegroups.com>
<t8c2q9$p06$1@gioia.aioe.org> <5844f300-546d-48a5-884f-f10c2078b084n@googlegroups.com>
<t8dekk$egm$1@gioia.aioe.org>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <0ac3789b-098e-4787-96c2-c5dd07b7629dn@googlegroups.com>
Subject: Re: trying to match a "word", having difficulty with a "Lookbehind assertion"
From: scott@sauyet.com (Scott Sauyet)
Injection-Date: Wed, 15 Jun 2022 20:32:31 +0000
Content-Type: text/plain; charset="UTF-8"
 by: Scott Sauyet - Wed, 15 Jun 2022 20:32 UTC

R.Wieser wrote:

> Imagine that I have "g**d***" somewhere in the text, but no replacement for
> it yet. But I already have "d***" as a searchstring. In that case that
^^^ ^^^^^^^
> "g**d***" should stay as it is.

I'm not sure what is meant here by "yet" and "already". Is there some
temporal change at play? Do you have a good example of an input structure,
perhaps a list of search strings and their (possible?) replacements and an
input string together with the expected output?

Or possibly a few such examples?

I'm now getting intrigued, but I still don't really understand the problem.

Also, is this an attempt to solve a real-world problem or is mostly a way to
noodle with more advanced regexes?

-- Scott

Re: trying to match a "word", having difficulty with a "Lookbehind assertion"

<t8elgm$m2f$1@gioia.aioe.org>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=5263&group=comp.lang.javascript#5263

  copy link   Newsgroups: comp.lang.javascript
Path: i2pn2.org!i2pn.org!aioe.org!XakcSTEO51npqVb7OVl71w.user.46.165.242.75.POSTED!not-for-mail
From: address@not.available (R.Wieser)
Newsgroups: comp.lang.javascript
Subject: Re: trying to match a "word", having difficulty with a "Lookbehind assertion"
Date: Thu, 16 Jun 2022 09:16:30 +0200
Organization: Aioe.org NNTP Server
Lines: 42
Message-ID: <t8elgm$m2f$1@gioia.aioe.org>
References: <t6aath$15hc$1@gioia.aioe.org> <628b4693-e733-4d3d-bd00-8ab522e92262n@googlegroups.com> <t8c2q9$p06$1@gioia.aioe.org> <5844f300-546d-48a5-884f-f10c2078b084n@googlegroups.com> <t8dekk$egm$1@gioia.aioe.org> <0ac3789b-098e-4787-96c2-c5dd07b7629dn@googlegroups.com>
Injection-Info: gioia.aioe.org; logging-data="22607"; posting-host="XakcSTEO51npqVb7OVl71w.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
X-MSMail-Priority: Normal
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5512
X-RFC2646: Format=Flowed; Original
X-Notice: Filtered by postfilter v. 0.9.2
X-Priority: 3
X-Newsreader: Microsoft Outlook Express 6.00.2900.5512
 by: R.Wieser - Thu, 16 Jun 2022 07:16 UTC

Scott,

> I'm not sure what is meant here by "yet" and "already". Is there some
> temporal change at play?

The searchwords are added (by me) as I encounter them.

> Or possibly a few such examples?

Of what ? I've given several examples (of the basic problem and how your
approach does not quite work), but those are not the ones you seem to need.

> I'm now getting intrigued, but I still don't really understand the
> problem.

Ask yourself : does your approach solve the "this is a clbuttic mistake"
problem ?

'Cause *that* is what I am after - just not for regular words as recognised
by a RegExp (see "\w", "\W", "\b")

> Also, is this an attempt to solve a real-world problem or is mostly a way
> to noodle with more advanced regexes?

Yes ...

https://notalwaysright.com/some-people-shouldnt-be-allowed-to-drive-or-go-out-in-public/258702/

.... and yes

Discovering/learning how to solve certain problems is never wasted time to
me.

Also, do notice that I provided the correct solution in my first post.
Only later I found out that the "look behind assertion" method itself isn't
recognised by my FF v52 browsers JS. :-\

Regards,
Rudy Wieser

Re: trying to match a "word", having difficulty with a "Lookbehind assertion"

<6f36fa56-ab24-4ddc-9040-ea3c178b1546n@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=5264&group=comp.lang.javascript#5264

  copy link   Newsgroups: comp.lang.javascript
X-Received: by 2002:a05:6000:168a:b0:20f:d6e8:a5b with SMTP id y10-20020a056000168a00b0020fd6e80a5bmr5652327wrd.41.1655400790769;
Thu, 16 Jun 2022 10:33:10 -0700 (PDT)
X-Received: by 2002:a9d:459d:0:b0:60c:62a4:4b83 with SMTP id
x29-20020a9d459d000000b0060c62a44b83mr2487585ote.69.1655400790028; Thu, 16
Jun 2022 10:33:10 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.128.88.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.javascript
Date: Thu, 16 Jun 2022 10:33:09 -0700 (PDT)
In-Reply-To: <t8elgm$m2f$1@gioia.aioe.org>
Injection-Info: google-groups.googlegroups.com; posting-host=170.202.22.116; posting-account=jEz2WAoAAABPN6KvjkIr_ZIYJY4YFml9
NNTP-Posting-Host: 170.202.22.116
References: <t6aath$15hc$1@gioia.aioe.org> <628b4693-e733-4d3d-bd00-8ab522e92262n@googlegroups.com>
<t8c2q9$p06$1@gioia.aioe.org> <5844f300-546d-48a5-884f-f10c2078b084n@googlegroups.com>
<t8dekk$egm$1@gioia.aioe.org> <0ac3789b-098e-4787-96c2-c5dd07b7629dn@googlegroups.com>
<t8elgm$m2f$1@gioia.aioe.org>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <6f36fa56-ab24-4ddc-9040-ea3c178b1546n@googlegroups.com>
Subject: Re: trying to match a "word", having difficulty with a "Lookbehind assertion"
From: scott@sauyet.com (Scott Sauyet)
Injection-Date: Thu, 16 Jun 2022 17:33:10 +0000
Content-Type: text/plain; charset="UTF-8"
 by: Scott Sauyet - Thu, 16 Jun 2022 17:33 UTC

R.Wieser wrote:
> Scott Sauyet wrote:,

>> Or possibly a few such examples?

> Of what ? I've given several examples (of the basic problem and how your
> approach does not quite work), but those are not the ones you seem to need.

I have some examples below. I'm *hoping* that they capture at least a
good chunk of your requirements, but it's not clear to me. If there are
gaps, could you supply such an example showing what you expect and how
this differs from that?

>> I'm now getting intrigued, but I still don't really understand the
>> problem.

> Ask yourself : does your approach solve the "this is a clbuttic mistake"
> problem ?
>
> 'Cause *that* is what I am after - just not for regular words as recognised
> by a RegExp (see "\w", "\W", "\b")

I don't think that anything can comfortably reverse the clbuttic
mistake. If you were to try, you'd probably end up with a "bellyasson"
in your navel. What I think you're doing is trying to find a way to
reverse the manual censoring of, say, `g**d***` which is too unlikely to
be intended text, and restore `goddamn`.

I'm trying for something simpler, still using regex. But obviously if
you can't do this with regex, you can still fall back on a custom state
machine implementation. That would be a shame.

>> Also, is this an attempt to solve a real-world problem or is mostly a way
>> to noodle with more advanced regexes?

> Yes ...
>
> https://notalwaysright.com/some-people-shouldnt-be-allowed-to-drive-or-go-out-in-public/258702/
>
> ... and yes
>
> Discovering/learning how to solve certain problems is never wasted time to
> me.

No, but there is are different ways to answer the questions, "How do I
solve this real world problem?" and "How can I best use regex to solve
this problem?"

I don't know whether I should be trying to help you find a way to better
use regex to solve the problem, or looking more broadly at unrelated
techniques. That's why I asked.

> Also, do notice that I provided the correct solution in my first post.
> Only later I found out that the "look behind assertion" method itself isn't
> recognised by my FF v52 browsers JS. :-\

Right, you won't be able to use look-behind in FF before version 78. [1]
But as the current version is 101, and as version 52 was first released
more than five years ago, perhaps an update is in order?

Finally, here's another attempt, using a combination of a negative
look-behind before the target and a negative look-ahead after it. Does
this capture what you're trying to do?

```
const unclean = (w, r) => (s) =>
s .replace (new RegExp (
'\\b(?<!\\*)' + w .replace (/\*/g, '\\*') + '(?![\w*])',
'gi'
), r);

unclean ("g**d***", "goddamn") (""... a g**d*** word ...)
//=> "... a goddamn word ..."
unclean ("g**d***", "goddamn") (""... a d*** word ...)
//=> "... a d*** word ..."
unclean ("d***", "damn") (""... a g**d*** word ...)
//=> "... a g**d*** word ..."
unclean ("d***", "damn") (""... a d*** word ...)
//=> "... a damn word ..."
unclean ("d***", "damn") (""d*** this, d*** that, d*** everything!)
//=> "damn this, damn that, damn everything!"
unclean ("d***", "damn") (""Frankly, my dear, I don't give a d***!)
//=> "Frankly, my dear, I don't give a damn!"
unclean ("d***", "damn") (""Would I knew the villain! / I would lam-d*** him)
//=> "Would I knew the villain! / I would lam-damn him"
unclean ("d***", "damn") (""Teacher, what does 'landd***e' mean?)
//=> "Teacher, what does 'landd***e' mean?"
```

-- Scott

[1]: <https://caniuse.com/js-regexp-lookbehind>

Re: trying to match a "word", having difficulty with a "Lookbehind assertion"

<t8fvmf$1ogl$1@gioia.aioe.org>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=5265&group=comp.lang.javascript#5265

  copy link   Newsgroups: comp.lang.javascript
Path: i2pn2.org!i2pn.org!aioe.org!XakcSTEO51npqVb7OVl71w.user.46.165.242.75.POSTED!not-for-mail
From: address@not.available (R.Wieser)
Newsgroups: comp.lang.javascript
Subject: Re: trying to match a "word", having difficulty with a "Lookbehind assertion"
Date: Thu, 16 Jun 2022 21:18:31 +0200
Organization: Aioe.org NNTP Server
Lines: 54
Message-ID: <t8fvmf$1ogl$1@gioia.aioe.org>
References: <t6aath$15hc$1@gioia.aioe.org> <628b4693-e733-4d3d-bd00-8ab522e92262n@googlegroups.com> <t8c2q9$p06$1@gioia.aioe.org> <5844f300-546d-48a5-884f-f10c2078b084n@googlegroups.com> <t8dekk$egm$1@gioia.aioe.org> <0ac3789b-098e-4787-96c2-c5dd07b7629dn@googlegroups.com> <t8elgm$m2f$1@gioia.aioe.org> <6f36fa56-ab24-4ddc-9040-ea3c178b1546n@googlegroups.com>
Injection-Info: gioia.aioe.org; logging-data="57877"; posting-host="XakcSTEO51npqVb7OVl71w.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
X-MSMail-Priority: Normal
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5512
X-Priority: 3
X-RFC2646: Format=Flowed; Original
X-Newsreader: Microsoft Outlook Express 6.00.2900.5512
X-Notice: Filtered by postfilter v. 0.9.2
 by: R.Wieser - Thu, 16 Jun 2022 19:18 UTC

Scott,

>> Ask yourself : does your approach solve the "this is a clbuttic mistake"
>> problem ?
....
> I don't think that anything can comfortably reverse the clbuttic
> mistake.

Than start with thinking how *not* to make it. 'Cause /that is all/ what my
problem is about.

I've already tried to explain it, but here it goes again :

* * * * * * * * * * * * * *

When I'm replacing all instances of "ass" in a piece of text I DO NOT WANT
to see "classic" being converted into "clbuttic".

* * * * * * * * * * * * * *

Replace "ass" with "d***" and "classic" with "g**d***" and you have my
example of two posts back.

> What I think you're doing is trying to find a way to reverse the manual
> censoring of, say, `g**d***` which is too unlikely to be intended text,
> and
> restore `goddamn`

Manual or not, yes, that is indeed what I'm doing ...

..... And *not at all* what my question is about.

> No, but there is are different ways to answer the questions, "How do I
> solve this real world problem?" and "How can I best use regex to solve
> this problem?"

The problem with the above is that you are second-guessing what I "really"
want to know.

Don't.

> Finally, here's another attempt, using a combination of a negative
> look-behind before the target and a negative look-ahead after it.

Sigh.

Look at the subjectline. What does that tell you ?

Also take a quick peek at the last few lines of my second message.

Regards,
Rudy Wieser

Re: trying to match a "word", having difficulty with a "Lookbehind assertion"

<c134d484-f27f-4341-bbde-6292e2dec094n@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=5266&group=comp.lang.javascript#5266

  copy link   Newsgroups: comp.lang.javascript
X-Received: by 2002:adf:e28a:0:b0:210:b31:722 with SMTP id v10-20020adfe28a000000b002100b310722mr7745363wri.65.1655447691950;
Thu, 16 Jun 2022 23:34:51 -0700 (PDT)
X-Received: by 2002:a4a:6118:0:b0:40e:6171:d69c with SMTP id
n24-20020a4a6118000000b0040e6171d69cmr3377293ooc.13.1655447691208; Thu, 16
Jun 2022 23:34:51 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.128.88.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.javascript
Date: Thu, 16 Jun 2022 23:34:51 -0700 (PDT)
In-Reply-To: <t6aath$15hc$1@gioia.aioe.org>
Injection-Info: google-groups.googlegroups.com; posting-host=82.131.37.239; posting-account=_HrVLgoAAAAvDDvVYw-sidhilgYzxTuh
NNTP-Posting-Host: 82.131.37.239
References: <t6aath$15hc$1@gioia.aioe.org>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <c134d484-f27f-4341-bbde-6292e2dec094n@googlegroups.com>
Subject: Re: trying to match a "word", having difficulty with a "Lookbehind assertion"
From: ingel1983912@gmail.com (Кристьян Робам)
Injection-Date: Fri, 17 Jun 2022 06:34:51 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
 by: Кристьян Р - Fri, 17 Jun 2022 06:34 UTC

Hyviä seksikuvia sinulle..... -------------> https://www.sexpicturespass.com/xxx/gay-big-dick-sucking.html


R.Wieser kirjutas Laupäev, 21. mai 2022 kl 11:21:00 UTC+2:
> Hello all,
>
> I'm trying to match group of characters, delimited by anything that does not
> belong in that group.
>
> Case in point: "Couldn't understand a g**d*** word she was saying!"
>
> I would like to match the "g**d***" sequence of letters.
>
> For that I've tried to use a RegEx :
>
> RegExp("(?<=[^a-zA-Z\*])"+escapeRegExp(find)+"(?=[^a-zA-Z\*])",'gi')
>
> -or-
>
> RegExp("(?<![a-zA-Z\*])"+escapeRegExp(find)+"(?=[^a-zA-Z\*])",'gi')
>
> ("escapeRegExp()" escapes the "*" to "\*")
>
> The problem is that neither of the above seem to match anything.
>
> When I use the following
>
> RegExp("\ \b"+escapeRegExp(find)+"(?=[^a-zA-Z\*])",'gi')
>
> (no space between the first two slashes. Had to insert it otherwise my
> newsclient turns it into a link)
>
> all goes well - but for the problem that than the partial "d***" is matched
> before "g**d***", throwing everything off.
>
>
> Question: if not the above, what /am/ I suppose to use as the "look behind
> assertion" ?
>
> Regards,
> Rudy Wieser

Re: trying to match a "word", having difficulty with a "Lookbehind assertion"

<3a961c41-ecd2-4dd3-8451-66623496ffbfn@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=5267&group=comp.lang.javascript#5267

  copy link   Newsgroups: comp.lang.javascript
X-Received: by 2002:a5d:4a88:0:b0:214:1e17:9993 with SMTP id o8-20020a5d4a88000000b002141e179993mr9871026wrq.608.1655485018400;
Fri, 17 Jun 2022 09:56:58 -0700 (PDT)
X-Received: by 2002:a05:6808:1527:b0:32e:e4a0:d819 with SMTP id
u39-20020a056808152700b0032ee4a0d819mr5879488oiw.237.1655485017535; Fri, 17
Jun 2022 09:56:57 -0700 (PDT)
Path: i2pn2.org!i2pn.org!aioe.org!feeder1.feed.usenet.farm!feed.usenet.farm!news.uzoreto.com!feeder1.cambriumusenet.nl!feed.tweak.nl!209.85.128.87.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.javascript
Date: Fri, 17 Jun 2022 09:56:57 -0700 (PDT)
In-Reply-To: <t8fvmf$1ogl$1@gioia.aioe.org>
Injection-Info: google-groups.googlegroups.com; posting-host=170.202.22.104; posting-account=jEz2WAoAAABPN6KvjkIr_ZIYJY4YFml9
NNTP-Posting-Host: 170.202.22.104
References: <t6aath$15hc$1@gioia.aioe.org> <628b4693-e733-4d3d-bd00-8ab522e92262n@googlegroups.com>
<t8c2q9$p06$1@gioia.aioe.org> <5844f300-546d-48a5-884f-f10c2078b084n@googlegroups.com>
<t8dekk$egm$1@gioia.aioe.org> <0ac3789b-098e-4787-96c2-c5dd07b7629dn@googlegroups.com>
<t8elgm$m2f$1@gioia.aioe.org> <6f36fa56-ab24-4ddc-9040-ea3c178b1546n@googlegroups.com>
<t8fvmf$1ogl$1@gioia.aioe.org>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <3a961c41-ecd2-4dd3-8451-66623496ffbfn@googlegroups.com>
Subject: Re: trying to match a "word", having difficulty with a "Lookbehind assertion"
From: scott@sauyet.com (Scott Sauyet)
Injection-Date: Fri, 17 Jun 2022 16:56:58 +0000
Content-Type: text/plain; charset="UTF-8"
 by: Scott Sauyet - Fri, 17 Jun 2022 16:56 UTC

R.Wieser wrote:
> Scott Sauyet wrote:

>> I don't think that anything can comfortably reverse the clbuttic
>> mistake.

> Than start with thinking how *not* to make it. 'Cause /that is all/ what my
> problem is about.

Sigh.

The code I've supplied is exactly an attempt to do this. It seems to
work for this case:

const unclean = (w, r) => (s) =>
s .replace (new RegExp (
'\\b(?<!\\*)' + w .replace (/\*/g, '\\*') + '(?![\w*])',
'gi'
), r);

unclean ('ass', 'butt') ('The law is an ass')
//=> "The law is an butt"
unclean ('ass', 'butt') ('Another classic mistake')
//=> "Another classic mistake"


> I've already tried to explain it, but here it goes again :
>
> When I'm replacing all instances of "ass" in a piece of text I DO NOT WANT
> to see "classic" being converted into "clbuttic".

Thank you. That's nice and clear. Look above and see if, as an outsider,
you would infer this from what you've said. I certainly didn't. All your
`g**d***` discussion made it sound like someone had already done some
conversion on plain, possibly obscenity-laced text, and that you were
trying to reverse it.

So are there cases my code doesn't handle?

>> No, but there is are different ways to answer the questions, "How do I
>> solve this real world problem?" and "How can I best use regex to solve
>> this problem?"

> The problem with the above is that you are second-guessing what I "really"
> want to know.
>
> Don't.

An attempt to tease out actual requirements from someone who thinks he's
being clear, but hasn't communicated them well enough for you to
understand, is substantially different from second-guessing what he wants.

>> Finally, here's another attempt, using a combination of a negative
>> look-behind before the target and a negative look-ahead after it.

> Sigh.

Even your updated problem statement above does not tell me what that
sigh is about.

> Look at the subjectline. What does that tell you ?

That you're having some issue with your attempt at a look-behind
solution to the problem of "trying to match a 'word'. Nothing there
tells me whether you want to make negative look-behind work properly
or whether you want to do this with regex in another way or if you're
open to non-regex solutions, or if you just want to b****-and-moan
(:->) about the state of the world.

> Also take a quick peek at the last few lines of my second message.

I believe I already offered a solution to that with:

| Right, you won't be able to use look-behind in FF before version 78.
| But as the current version is 101, and as version 52 was first released
| more than five years ago, perhaps an update is in order?

As far as I can tell, I've written a function that matches your problem
statement, and matched it before you made that statement explicit. If
it doesn't match it, can you show an example that still fails, or give
further clarifications to the statement? If you are saying that it has
to work in five-year old Firefox, does it also have to work in 25-year
old Netscape? (Regex was not added until ES3 -- I know because I had to
implement a partial regex interpreter in ES1/2 JS -- not fun!) If it
must be a regex solution, please make that clear. Conversely, if it
cannot be regex, also make that clear.

My mind-reading days are long over.

-- Scott

Re: trying to match a "word", having difficulty with a "Lookbehind assertion"

<e55b6035-8f1e-4d98-b1a2-682e6b436d95n@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=5322&group=comp.lang.javascript#5322

  copy link   Newsgroups: comp.lang.javascript
X-Received: by 2002:a37:9dc5:0:b0:6b2:4cf9:86dc with SMTP id g188-20020a379dc5000000b006b24cf986dcmr22105221qke.747.1657124029493;
Wed, 06 Jul 2022 09:13:49 -0700 (PDT)
X-Received: by 2002:a05:6808:4cd:b0:335:6fbe:e1fd with SMTP id
a13-20020a05680804cd00b003356fbee1fdmr22825710oie.48.1657124029015; Wed, 06
Jul 2022 09:13:49 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.javascript
Date: Wed, 6 Jul 2022 09:13:48 -0700 (PDT)
In-Reply-To: <t6aath$15hc$1@gioia.aioe.org>
Injection-Info: google-groups.googlegroups.com; posting-host=82.131.37.215; posting-account=_HrVLgoAAAAvDDvVYw-sidhilgYzxTuh
NNTP-Posting-Host: 82.131.37.215
References: <t6aath$15hc$1@gioia.aioe.org>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <e55b6035-8f1e-4d98-b1a2-682e6b436d95n@googlegroups.com>
Subject: Re: trying to match a "word", having difficulty with a "Lookbehind assertion"
From: ingel1983912@gmail.com (Härra Rabmo)
Injection-Date: Wed, 06 Jul 2022 16:13:49 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 47
 by: Härra Rabmo - Wed, 6 Jul 2022 16:13 UTC

Hey guy. Would You want to get rich with me doing programming? If yes, call me !!!!!!!!!

✆☎☏📱📞 : 372 53900660

R.Wieser kirjutas Laupäev, 21. mai 2022 kl 11:21:00 UTC+2:
> Hello all,
>
> I'm trying to match group of characters, delimited by anything that does not
> belong in that group.
>
> Case in point: "Couldn't understand a g**d*** word she was saying!"
>
> I would like to match the "g**d***" sequence of letters.
>
> For that I've tried to use a RegEx :
>
> RegExp("(?<=[^a-zA-Z\*])"+escapeRegExp(find)+"(?=[^a-zA-Z\*])",'gi')
>
> -or-
>
> RegExp("(?<![a-zA-Z\*])"+escapeRegExp(find)+"(?=[^a-zA-Z\*])",'gi')
>
> ("escapeRegExp()" escapes the "*" to "\*")
>
> The problem is that neither of the above seem to match anything.
>
> When I use the following
>
> RegExp("\ \b"+escapeRegExp(find)+"(?=[^a-zA-Z\*])",'gi')
>
> (no space between the first two slashes. Had to insert it otherwise my
> newsclient turns it into a link)
>
> all goes well - but for the problem that than the partial "d***" is matched
> before "g**d***", throwing everything off.
>
>
> Question: if not the above, what /am/ I suppose to use as the "look behind
> assertion" ?
>
> Regards,
> Rudy Wieser

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor