We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Explanation:
(?<= ) is a look behind positive. This ensures the characters are preceeded by a space.
(?= ) is a look ahead positive. This ensures the characters are followed by a space.
Finally, the string in question contains characters which themselves are used in regex statement, so they must be escaped with a backslash to be recognized!
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Regex Substitution
You are viewing a single comment's thread. Return to all comments →
and_pattern = "(?<= )\&\&(?= )" or_pattern = "(?<= )||(?= )"
Explanation: (?<= ) is a look behind positive. This ensures the characters are preceeded by a space. (?= ) is a look ahead positive. This ensures the characters are followed by a space. Finally, the string in question contains characters which themselves are used in regex statement, so they must be escaped with a backslash to be recognized!