Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #40874 > unrolled thread

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

Started by"R.Wieser" <address@not.available>
First post2022-05-21 11:20 +0200
Last post2022-07-06 09:13 -0700
Articles 3 on this page of 23 — 7 participants

Back to article view | Back to comp.lang.javascript


Contents

  trying to match a "word", having difficulty with a "Lookbehind assertion" "R.Wieser" <address@not.available> - 2022-05-21 11:20 +0200
    Re: trying to match a "word", having difficulty with a "Lookbehind assertion" The Natural Philosopher <tnp@invalid.invalid> - 2022-05-21 11:17 +0100
      Re: trying to match a "word", having difficulty with a "Lookbehind assertion" "R.Wieser" <address@not.available> - 2022-05-22 13:42 +0200
        Re: trying to match a "word", having difficulty with a "Lookbehind assertion" The Natural Philosopher <tnp@invalid.invalid> - 2022-05-22 13:03 +0100
          Re: trying to match a "word", having difficulty with a "Lookbehind assertion" "R.Wieser" <address@not.available> - 2022-05-22 17:42 +0200
            Re: trying to match a "word", having difficulty with a "Lookbehind assertion" The Natural Philosopher <tnp@invalid.invalid> - 2022-05-23 13:57 +0100
    Re: trying to match a "word", having difficulty with a "Lookbehind assertion" JJ <jj4public@gmx.com> - 2022-05-21 19:13 +0700
      Re: trying to match a "word", having difficulty with a "Lookbehind assertion" "R.Wieser" <address@not.available> - 2022-05-21 16:33 +0200
      Re: trying to match a "word", having difficulty with a "Lookbehind assertion" "R.Wieser" <address@not.available> - 2022-05-21 19:45 +0200
      Re: trying to match a "word", having difficulty with a "Lookbehind assertion" Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2022-06-09 00:14 +0200
        Re: trying to match a "word", having difficulty with a "Lookbehind assertion" "R.Wieser" <address@not.available> - 2022-06-09 09:16 +0200
        Re: trying to match a "word", having difficulty with a "Lookbehind assertion" Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2022-06-09 12:21 +0200
    Re: trying to match a "word", having difficulty with a "Lookbehind assertion" Scott Sauyet <scott@sauyet.com> - 2022-06-14 10:56 -0700
      Re: trying to match a "word", having difficulty with a "Lookbehind assertion" "R.Wieser" <address@not.available> - 2022-06-15 09:47 +0200
        Re: trying to match a "word", having difficulty with a "Lookbehind assertion" Scott Sauyet <scott@sauyet.com> - 2022-06-15 12:42 -0700
          Re: trying to match a "word", having difficulty with a "Lookbehind assertion" "R.Wieser" <address@not.available> - 2022-06-15 22:15 +0200
            Re: trying to match a "word", having difficulty with a "Lookbehind assertion" Scott Sauyet <scott@sauyet.com> - 2022-06-15 13:32 -0700
              Re: trying to match a "word", having difficulty with a "Lookbehind assertion" "R.Wieser" <address@not.available> - 2022-06-16 09:16 +0200
                Re: trying to match a "word", having difficulty with a "Lookbehind assertion" Scott Sauyet <scott@sauyet.com> - 2022-06-16 10:33 -0700
                  Re: trying to match a "word", having difficulty with a "Lookbehind assertion" "R.Wieser" <address@not.available> - 2022-06-16 21:18 +0200
                    Re: trying to match a "word", having difficulty with a "Lookbehind assertion" Scott Sauyet <scott@sauyet.com> - 2022-06-17 09:56 -0700
    Re: trying to match a "word", having difficulty with a "Lookbehind assertion" Кристьян Робам <ingel1983912@gmail.com> - 2022-06-16 23:34 -0700
    Re: trying to match a "word", having difficulty with a "Lookbehind assertion" Härra Rabmo <ingel1983912@gmail.com> - 2022-07-06 09:13 -0700

Page 2 of 2 — ← Prev page 1 [2]


#40914

FromScott Sauyet <scott@sauyet.com>
Date2022-06-17 09:56 -0700
Message-ID<3a961c41-ecd2-4dd3-8451-66623496ffbfn@googlegroups.com>
In reply to#40912
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

[toc] | [prev] | [next] | [standalone]


#40913

FromКристьян Робам <ingel1983912@gmail.com>
Date2022-06-16 23:34 -0700
Message-ID<c134d484-f27f-4341-bbde-6292e2dec094n@googlegroups.com>
In reply to#40874
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

[toc] | [prev] | [next] | [standalone]


#40969

FromHärra Rabmo <ingel1983912@gmail.com>
Date2022-07-06 09:13 -0700
Message-ID<e55b6035-8f1e-4d98-b1a2-682e6b436d95n@googlegroups.com>
In reply to#40874
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

[toc] | [prev] | [standalone]


Page 2 of 2 — ← Prev page 1 [2]

Back to top | Article view | comp.lang.javascript


csiph-web