Computing desk | ||
---|---|---|
< May 26 | << Apr | May | Jun >> | May 28 > |
Welcome to the Wikipedia Computing Reference Desk Archives |
---|
The page you are currently viewing is a transcluded archive page. While you can leave answers for any questions shown below, please ask new questions on one of the current reference desk pages. |
With regular expressions (I am using the perl variety), how do you capture a character and then match any character except that one?
I tried /(.)[^\1]/ but apparently back references don't work in groups. I tried to match (say) "banana" with something like /(.)(.)([^\1])\2\3\2/ which doesn't work. -- SGBailey (talk) 06:43, 27 May 2022 (UTC)
banana, but will also match
baaaaa. Note that (?!\1) is not in itself a character or group - my terminology might be wrong here, but anyway, I mean you can't refer back to it, it's not \3. It just looks ahead past the preceding character to check a fact about the next one.
banana,
bbnbnband
bababa.