regular expressions – Regexp: Regexp that matches “)” but NOT “()”

I am writing a function that needs to move the character back to the first “)” character. However, in the middle there might be a “()” characters, I do NOT want the cursor to go there.

HOWEVER, if there are no “()” characters, then I simply want to go to the first “)”

How could I go about doing this? My first instinct was using regex or rx; but I am a complete regex novice.

Btw here’s an example:

fn this_is_a_function(args) -> Result<(), Err> {                          
}

I want the re-search-backwards function to match the “)” after args and ignore the “)” in Result<(), ...

I tried using "[^(])" but if fails in this example:

fn this_is_a_function() { 

}                         

When you call the re-search-backwards with that regexp, you get the following error
foo: Search failed: "[^(])"

Read more here: Source link