简体   繁体   中英

Notepad++ Find/Replace Regex Help

I am having issues doing a string replacement in Notepad++, and need some help.

My file:

LastName,(tab)FirstName[optional]MiddleName

Some times there is data that has a middle name, sometimes not.

Public,JohnQ.
Doe,John
Clinton,WilliamJefferson

would be:

Public(tab)John(tab)Q
Doe(tab)John
Clinton(tab)William(tab)Jefferson

I want to split it out into this:

LastName(tab)FirstName(tab)MiddleName

Thanks for adding the sample input. It helps immensely to have that around. Try this and see if it does what you want.

Find, making sure Match case is checked:

([A-Z][a-z]*),([A-Z][a-z]*)(.*)

Replace with:

\1(tab)\2(tab)\3

Of course, (tab) is actually a tab character that you have to place in the replacement string yourself.

An ugly regex like this works for me on the example you've provided:

(\w+),(\w+?)(([A-Z]\w*\.?)?)\n

replace with

\1\t\2\t\3\n

Note:

  • This only works if the middle name starts with a letter in the AZ. You might be able to replace [AZ] with [[:upper:]] if notepad++ supports it (I don't know).
  • I need that second bracket around the middle name part because I need to match at least an empty string when there is no middle name.

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