简体   繁体   中英

How to find texts and replace them using RegEx

Below is an extract from my long text:

As a young researcher, he is required:
\n ÷ to read at least three theses\n ÷ to meet his tutor or supervisor 
once a week\n ÷ to join seminars\n

Now I would like to find any blocks starting with ÷ and ending with \\n , and replace ÷ by ÷<font color="blue"> and \\n by </font>\\n . So, for example, my above extract would appear like this:

As a young researcher, he is required:
\n ÷<font color="blue"> to read at least three theses</font>\n ÷<font color="blue"> 
to meet his tutor or supervisor once a week</font>\n ÷<font color="blue"> to join seminars</font>\n

So far I have been using these Grep in TextWrangler to look for and replace:

(÷[^ \t/<>]*?).*?([^ \t/<>]*?\\n)

<font color="blue">\1\2</font>\3

The required blocks of text are successfully found, but replacing doesn't work as I expect.

I'm using TextWrangler, but may have access to BBEdit or Notepad++.

Can you please help me to solve this problem? Thank you very much.


UPDATE

Thanks to DesertEagle, I have worked out the solution. Here is the code:

÷([^\\n]+)\\n
÷<font color="blue">\1</font>\\n

Though I don't have textwrangler at hand, this should work for you [1]

search /÷([^\\n]+)\\n/

EDIT The correct syntax for textwrangler is ÷([^\\\\n]+)\\\\n

replace ÷<font color="blue">\\1</font>\\n

[1] please ensure proper escaping for your engine

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM