0

I need a pattern / search string to remove everything between the "[" and "]" characters. An example would be:

This study  [ref] is  a good example

This should become:

This study  is  a good example

I found this regex here \<(*{1,})\> but although it works with < and >, it doesn't with [ and ].

When I use \[(*{1,})\] world "says" that they can't find what I am looking for.

I am trying to remove some formatings from wikipedia articles and this regex doesn't remove the [edit] next to the headings. (I use the merge formating paste)

MagTun
  • 1,378
  • 4
  • 23
  • 33
  • Technically it's not regex if it's ms word. as this link mentions. http://superuser.com/questions/890288/how-can-i-do-find-and-replace-with-regex-on-microsoft-word And also, If you are editing a wiki page you lose nothing(no formatting), by cut and pasting it into a program that supports regex, then using a regex – barlop Dec 10 '15 at 09:06
  • Sorry for using regex, I meant wildcard. I am using Word, because I need to keep the heading style (and the automating numbering with it) that Word proposes. Notepad++ doesn't do that – MagTun Dec 10 '15 at 09:10
  • The `\ ` escapes special characters such as `[` and `]`. Therefore, if you checked "use wildcards" in the Find & Replace dialog, you need to escape them as `\[` and `\]`. – daniel.heydebreck Dec 10 '15 at 09:12
  • Sorry I forgot to include my regex : `\[(*{1,})\]`.Somehow, this doesn't match the `[edit]` next to the heading of a wikipedia article – MagTun Dec 10 '15 at 09:16
  • @Arone did you try clicking the cursor at the beginning of the document before you clicked find? – barlop Dec 10 '15 at 09:18
  • According to https://support.office.com/en-ca/article/Use-wildcard-characters-to-find-or-replace-text-610e37dc-bb2f-4a8b-8fa5-aa991160eafb, `*` represents already an arbitrary number of string characters. Therefore, you can drop `{1,}`. Alternatively, you could write `\[[a-zA-Z ]{1,}\]`. The `(` and `)` are also not needed. – daniel.heydebreck Dec 10 '15 at 09:31

1 Answers1

2

This two expressions work

\[*\]
\[[a-zA-Z ]{1,}\]

Further comments:

  • * represents an arbitrary number of string characters. {1,} can only be attached to a single character wildcard. That is the problem with the expression \[*{1,}\].
  • The ( and ) are not necessary.

See https://support.office.com/en-ca/article/Use-wildcard-characters-to-find-or-replace-text-610e37dc-bb2f-4a8b-8fa5-aa991160eafb for details on the wildcards.