Skip to content
Advertisement

Regex discard catch between strings

I wrote this regex: (?<![.#])bMY_STRINGb(?![#])(?!.*(;video))

With the intention to search for a string not containing . or # preceding it, and no # succeeding, it also checks if at the ending does not contain the word ;video.

I’m trying now in how I could also check for if between the found string exist a comma before it, and the text ;comment after it, if so then don’t catch this string.

Examples:

JavaScript

The needle regex must obey the things I’m trying to catch as described at the beginning of the thread.

Edit: added more samples on the examples above, also:

Q- Why should there be a match in text,MY_STRING,text ;comment? The MY_STRING is preceded with, and is followed with ;comment some chars after.

Because there’s a comma after the string, in this case, she can be caught, but if it was any other special char the don’t, example:

JavaScript

Added the examples here: https://regex101.com/r/himCtG/2/

Guys, I know its confusing, I spent hours trying my best to make it clearer, please don’t negative my question, I really need/appreciate any help on it, if there’s something unclearer tag me and I’m asap will answer.

Advertisement

Answer

Your description is not entirely clear but I think I got the idea; how about this:

JavaScript

With the updated samples I came up with this pattern that seems to cover all cases; though I still feel not all possible permutations are covered:

JavaScript

Demo

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement