-2

I am trying to make a regular expression capture any words in the specific line after the word Attachment:

This question is for work, so it is not a homework or test question. I took the paragraph below as an example from www.regular-expressions.info. I did not major in computers but Psychology so this is completely foreign to me. I've read the manuals for the last two days, and because this is going over my head, I don't know how to begin.

I have a task which involves me linking the attachments to a specific file with the same name saved in a folder (at least 500 attachments) on Adobe PDF. What I did before was to manually select the words and link it to a specific file in a folder, but it is tedious to do when they can go up to 500 attachments.

I was aware of an application plug-in called EVERMAP that you can download for Adobe to automatically link specific words to a specific file in a folder. However, it requires me to use regular expressions which again, I don't know how to use.

I will bold the words I want to capture in the paragraph below.

The repetition operator manual expand the match as far as they, and only come back if they must to satisfy the remainder.

Attachment: The repetition operator manual

The asterisk or star tells the engine to attempt to match the preceding token zero or more times. The plus tells the engine to attempt to match the preceding token once or more.

Attachment: Asterisk and stars engine

Community
  • 1
  • 1
A.Li
  • 1
  • 1
  • 3
    Welcome to Stack Overflow! Please [take the tour](http://stackoverflow.com/tour), have a look at the help center, in particular [how to ask a good question?](http://stackoverflow.com/help/how-to-ask). What part are you stuck on? What have you tried? – Maciej Lach Apr 22 '16 at 17:19
  • You haven't shown us what you've tried, and this sounds like homework or a test question, especially the part that you pasted that says "The asterisk or star tells the engine to attempt to match the preceding token zero or more times. The plus tells the engine to attempt to match the preceding token once or more." – j08691 Apr 22 '16 at 17:28
  • This is for work, definitely not a homework or test question. I took the paragraph as an example from regular expressions.info. I did not major in computer anything but in Psychology so this is completely new to me. I've read the manuals for the last two days, and because this is completely foreign to me, I don't know how to begin. I have a deadline for work which involves me linking the attachments to a specific file with the same name saved in a folder by making a regular expression on an application called "EVERMAP" which is a plugin for Adobe. – A.Li Apr 22 '16 at 17:45
  • 1
    If you really already read the Regex manual, you should be able to show your failed Regex. I know it's for work. It's still a homework but the office version. – Aminah Nuraini Apr 23 '16 at 00:16

2 Answers2

1

Attachment: (.+) should work in your case unless there are other exceptions to this rule. The regex simply tells the parser to capture 1 or more character after the word Attachment:. See here for the sample

Kevin Pei
  • 268
  • 1
  • 3
  • 12
1

Like @Kevin said, the Regex is simple. Use Attachment: (.+).

Maybe you are confused on how to use Regex. I don't know about the Evermap plugin, but you can copy all the text from the PDF to Sublime Text (text editor to open .txt but with a lot of features) and do Regex part there. And then, since you are not a programmer, you should remove other irrelevant data. So the Regex will be:

`^\s*Attachment:\s*(.+)$|^(?!Attachment:).+$`

And replace it with:

`\1`

\1 is a variable containing group value caught in ()

In Sublime Text find Find and Replace, then apply the Regex there. Don't forget to turn on the Regex mode.

Aminah Nuraini
  • 18,120
  • 8
  • 90
  • 108