bhanquier Posted January 19, 2020 Posted January 19, 2020 Hi, I'm looking for a way to surround selected text with the usual (I think html?) codes for bold, italic and strike ( [b][/b] ) with a keyboard shortcut. Nothing fancy nor extensive. I understand one can do this with the Transform function in Alfred. Problem is, as far as I understand it would have to be done using a regex? I would add my voice to the usual "just learn it", but the maybe twice I've approached regex in my entire life (and I'm no spring chicken) I've felt as if I was trying to climb a mountain to get to a pebble, maybe usual, but not a diamond. So, I humbly ask: would anyone with knowledge of the Dark Arts be kind enough to help me? One example of the structure would be great, I think I'm not that dumb that I couldn't adapt to the others. Thanks for the generous one(s).
deanishe Posted January 19, 2020 Posted January 19, 2020 (edited) That's BBCode, not HTML. HTML would be <b></b>. Generally, regular expressions are total overkill for just surrounding some text with tags, but that's the only tool Alfred gives you for the job. You want a Replace utility set up like this: The regular expression .+ means "one or more of any character", and the brackets mean "this is a match group". In the replacement field, $1 means "contents of match group 1". So basically, "match anything and put it between [ b] and [/b]". Edited January 19, 2020 by deanishe
vitor Posted January 20, 2020 Posted January 20, 2020 Another way: connect a Hotkey Trigger (with Argument set to Selection in macOS) to a Copy to Clipboard Output (with Automatically paste to front most app ticked and the text box set to: [b]{query}[/b] deanishe 1
bhanquier Posted January 20, 2020 Author Posted January 20, 2020 Awesome! I adopted Vitor's solution, with deanishe's approval. Thanks so much to both of you!
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now