RegEx to replace char which shouldnt start and end with some char!! for both python and ?JavaScript


UseCase: Replace single occurrence of "_" which shouldn’t start and ends with "_".

mystr = "This_is_Something____funny__but_important" 
re.sub(r'(?<!_)(_(?!_))', '#', mystr) 
Note: If you want to modify for different char sets(for beginners)! replace below keywords
chars you want to play with.


var mystr = "This_is_Something____funny__but_important" 

mystr.replace(/([^_:])_(?!_)/g, '$1#'); 


Same here:

This is not the post to learn about python/java script.
Just a useful find for my pal abby Sheik. :)