-3

I am looking to replace a brand name in HTML but I want to avoid breaking brand mentions that might be part of a CSS class. I decided to try to allow only matches preceded by a space or a comma, but could be followed by anything except a dash, an underscore or a dot. But because a trailing dot could be a legitimate match, I want to allow it if t's followed by a space.

So far my regex looks like this:

([ ,])(brandname|brand name)(?![-_])

but I am stuck with how to negative match the trailing . but allow trailing .\s

Editing to give a few examples:

true:   brand name. something
false:  brandname.something
true:   ,brand name. something
false:  .brandname
true:   brandname something
true:   brandname,something
false:  brand name-something
michaeldon
  • 507
  • 3
  • 11
  • What does this mean `the trailing . but allow trailing .\s` ? –  Oct 01 '20 at 17:24
  • I really think you would have better chances of getting this answered if you provided an example of a string that you want to modify along with an example of what it should look like after the bran replacing – Kamil Janowski Oct 01 '20 at 17:27
  • @NiettheDarkAbsol - Why link this as a dup to that html post ? –  Oct 01 '20 at 17:40
  • @KamilJanowski sorry, I have added them in the original post. – michaeldon Oct 01 '20 at 17:47
  • @Maxt8r Because you DO NOT parse HTML with Regex. – Niet the Dark Absol Oct 01 '20 at 19:23
  • @NiettheDarkAbsol - Here I CAN parse HTML with REGEX _In 2 Languages_ PHP https://regex101.com/r/p0t1H8/1 Python - https://regex101.com/r/BF0zIp/1 –  Oct 01 '20 at 20:11
  • @Maxt8r ok Karen. – Niet the Dark Absol Oct 01 '20 at 20:36
  • 1
    @maxt8r yes I agree. I can do what I want. I don't need someone telling me what I am allowed to do. There is no DOM in apps script so there is no option to parse it. Thanks for your solution. It was exactly what I needed. – michaeldon Oct 02 '20 at 21:55
  • @NiettheDarkAbsol I doubt you know what ok Karen means or who Dane Cook is, but in your circle of lezbots I'm sure you have thrilling days in your life. –  Oct 02 '20 at 22:28

1 Answers1

0

I think this is what you're trying

[ ,]brand[ ]?name(?:(?![-_.])|(?=\.[ ]))

 [ ,]                # space or comma
 brand [ ]? name     # brand name 
 (?:                 # Check ahead assertion
    (?! [-_.] )      # Not dash, underscore or dot
  | (?= \. [ ] )     # Or, dot is ok if followed by space
 )