1

Good evening

I have got a question about some text editor. I am using CotEditor on Mac and I want to find and replace something special. I have an .csv data which I converted as an .txt data with numbers. In this list there are some kind of special words which I want to find and delete all other words.

For example:

Going with fancy looking rig this week. **@aaw_sg** W500 CIEM, with gold and silver flakes, combined with @nullaudio cable and my faithful Shanling M5

or

If you are in Czech republic this week, be sure to visit Audio Video show Praha 2018. Shanling will be represented by our Czech distributor Gothic @headphones.cz in room 332 on 3rd floor. Visit audio-video-show.cz for more info

I want to filter all @*!

Background is I want to follow some tagged sites on Instagram and do not want to klick each pic and follow.

Can someone help me?

3
  • Please clarify what you want to replace: do you mean the regular expression @*!, or all of the characters from the group [@*!], or something else?
    – AFH
    Mar 27, 2018 at 18:30
  • I mean all letters which begins at "@" and end with the next space. Mar 27, 2018 at 18:33
  • The RE is "@[^ ]* ", which you replace with " " (no quotes in either case, but included here to delimit the strings). This will not remove "@string" at the end of a line if there is no trailing space.
    – AFH
    Mar 27, 2018 at 18:51

3 Answers 3

1

Use something like @\S+.

Where:

  • @ means literally "@"
  • \S+ means 1 or more any character that is not a space.

Edit according to comment:

Using notepad++, you could do in one pass: (It also works in SublimeText)

  • Ctrl+H
  • Find what: (?:^|\G)[^@]+(@\S+|$)
  • Replace with: $1\n
  • check Wrap around
  • check Regular expression
  • Replace all

Explanation:

(?:     : non capture group
  ^     : beginning of line
 |      : R
  \G    : position of last match
)       : end group
[^@]+   : 1 or more any character that is not @
(       : start group 1
  @\S+  : @ followed by any non space character
 |      : OR
  $     : end of line
)       : end group 1

Replacement:

$1      : content of group 1
\n      : line feed, you could change it for the linebreak you need

Result for given example:

@aaw_sg
@nullaudio
@headphones.cz
3
  • Is it possible to see the opposite of what you suggested? Because your suggestion is doing the right way, but I only want to have all letters which begins at "@" and end with the next space. For example: From my first example there must only be: '@aaw_sg @nullaudio' My second example: '@headphones.cz' Mar 27, 2018 at 19:49
  • @SporeTinte049: I've updated my answer.
    – Toto
    Mar 28, 2018 at 8:22
  • @SporeTinte049: You're welcome, glad it helps.
    – Toto
    Mar 28, 2018 at 9:09
0

If the usage of your regex is Instagram account specific, @[a-zA-Z0-9._]+ would be the find string.

cf. Character Limit on Instagram Usernames -Stack Overflow

regex for removing all non-account characters

The following two-step regex would remove all characters but leave Instagram accounts.

  1. remove all non-account characters
    • find string: (@[a-zA-Z0-9._]+|^)(.+?)(?=@|$)
    • replacement string: $1
  2. insert spaces between accounts
    • find string: (?<=[a-zA-Z0-9._])@
    • replacement sting: @
3
  • With your regex it shows what I wanna have, but what’s the regex for showing the opposite. I wanna find all the not Instagram account specifics and replace them with nothing Mar 28, 2018 at 6:48
  • That's actually hard. I updated my original post. Do you mean something like this?
    – 1024jp
    Mar 28, 2018 at 7:43
  • Yes, but when I tip the first bullet of "remove all non-account characters" and klick on replace all: everything is deleted! Link for seeing the problem: ibb.co/fakAFS ibb.co/iuqcvS ibb.co/hKBvh7 Mar 28, 2018 at 8:36
0

In CudaText editor (free) you can make new text file with @nnn accounts:

  • call Find dialog, enter regex @[\w\.]+
  • press "Select all" button
  • copy selections to clipboard (Edit/Copy)
  • make new tab, paste from clipboard (Edit/Paste)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .