Jump to content

Help with regex


Recommended Posts

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). 

Link to comment

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:

 

image.png.831e39e739ae85835c094a0ce586354c.png

 

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 by deanishe
Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...