webblish
webblish

Reputation: 33

Dealing with square brackets in regular expressions in Notepad++

I'm converting a CSV file from the database of the Geeklog CMS to WordPress posts. Unfortunately, it contains soms 'autotags' (similar to the 'shortcodes' in WordPress), with square brackets.

I want to replace several hundreds of them to normal HTML code with search+replace in Notepad++ but can't find a way to deal with the square brackets.

This is the 'autotag' from Geeklog: [story:theslugofthepost13122005 The Anchor Text Of The Post]

I've found out that I can convert the "[story" part to <a href=" with the RegEx "\[]story" but can't find a way to find/select/convert the rest of the autotag. Any help woud be very appreciated!

Upvotes: 2

Views: 938

Answers (1)

epoch
epoch

Reputation: 16605

Set the replace options to Regular Expression:

I used this: (from what I could make out from your post):

Find What:    \[story:(\w+)\s+((\w+\s*)+)?\]
Replace With: <a href="$1">$2</a>

It replaces

[story:theslugofthepost13122005 The Anchor Text Of The Post]

with

<a href="theslugofthepost13122005">The Anchor Text Of The Post</a>

EDIT

Just to clarify, your main problem was that you were not escaping the square brackets, as they denote a character class in regex, so for example: [ should be \[

Upvotes: 1

Related Questions