I am in need of a JavaScript regex that can specifically select a single character with one condition: it must not be followed or preceded by a particular specified character.
The target character is /
, but I want to select it only if it is not immediately adjacent to the character a
.
For example:
str = "I Like this/ and a/ basketball is round a/a ups.Papa/ tol/d /me tha/t";
myregex = ????
var patt = new RegExp(myregex);
var res = patt.split(str);
The desired result should look like this:
res[0] = "I Like this"
res[1] = " and a/ basketball is round a/a ups.Papa/ tol"
res[2] = "d "
res[3] = "me tha/t"
The regex pattern needed is something along the lines of:
(if not a then)(\/)(if not a then)
I have attempted to create the regex using: [^a](\/)[^a]
, however, this also selects characters directly next to the /
such as s/
and l/d
, rather than just isolating the instances where the a
character is present. My goal is to exclude selections of characters beside the /
.