1

In another thread

grep search

got the proper use right for the OR argument in a grep search in BBEDIT and so was wondering whether this can be expanded as following :

is it possible to have a given set of different entries with different answers in the Find field or is it just one by one ?

Is there a (grep) symbol or script available to run the following queries as a single one :

string1|string2|string3|string4

Replace : string 5

stringA|stringB|stringC|stringD

Replace : string E

string@|string#|string$|string%

Replace : string £

For now I run each of these queries individually, but if it’s possible to group them together in a single find&replace query, that would be awesome !

Toto
  • 19,304

1 Answers1

0

Here is a way to do the job with Notepad++ or any tool that uses boost regex flavour.

  • Ctrl+H
  • Find what: (s1|s2|s3|s4)|(sA|sB|sC|sD)|(s@|s#|s\$|s%)
  • Replace with: (?1s5)(?2sE)(?3s£)
  • TICK Wrap around
  • SELECT Regular expression
  • Replace all

Explanation:

(s1|s2|s3|s4)       # group 1, 1 out 4 possibilities
  |                   # OR
(sA|sB|sC|sD)       # group 2, 1 out 4 possibilities
  |                   # OR
(s@|s#|s\$|s%)      # group 3, 1 out 4 possibilities

Replacement:

(?1         # if group 1 exists
  s5          # print s5
)           # endif
(?2sE)      # if group 2 exists, print SE
(?3s£)      # if group 3 exists, print $£

Screenshot (before):

enter image description here

Screenshot (after):

enter image description here

Toto
  • 19,304