English 中文(简体)
定期表示开始铺路,以在附注pad++中结束
原标题:Regular Expression to move beginning of string to end in Notepad++

I have a textfile like so:

marc_webber
john_grisham
rahmin_darfur
firstname_lastname

我希望这一产出也一样(如“万象”这样的双重名称):

Webber, Marc, marc_webber
Grisham, John, john_grisham
Darfur, Rahmin, rahmin_darfur
LastName, FirstName, firstname_lastname

So I want to split the strings at the _, move the last name to the beginning and comma delimit first name and the concatenated name to the end (and maybe even capitalize the first letter). This would be fairly easy with a programming language, but I want to know whether it is possible using Notepad++ s find and replace feature with regular expressions.
Basically I would need to create variables for the first name and the last name and string them together again in the end.

最佳回答

除临时工作外(在方案设计师笔记本中测试......):

Find Pattern:

((w+)_(w+))

<>Replace>:

3, 2, 1
问题回答

这对我来说是使用<代码>的<>。 (我猜测,由于可能支持常规表述,它也在附注pad++中工作):

$ sed -r  s/(w+)_(w+)/u2, u1, /  file.txt
Webber, Marc, marc_webber
Grisham, John, john_grisham
Darfur, Rahmin, rahmin_darfur
Lastname, Firstname, firstname_lastname

实现资本化,如你的例子,是使用<代码>u<>/代码>。

详情请见





相关问题
Uncommon regular expressions [closed]

Recently I discovered two amazing regular expression features: ?: and ?!. I was curious of other neat regex features. So maybe you would like to share some tricky regular expressions.

regex to trap img tag, both versions

I need to remove image tags from text, so both versions of the tag: <img src="" ... ></img> <img src="" ... />

C++, Boost regex, replace value function of matched value?

Specifically, I have an array of strings called val, and want to replace all instances of "%{n}%" in the input with val[n]. More generally, I want the replace value to be a function of the match ...

PowerShell -match operator and multiple groups

I have the following log entry that I am processing in PowerShell I m trying to extract all the activity names and durations using the -match operator but I am only getting one match group back. I m ...

Is it possible to negate a regular expression search?

I m building a lexical analysis engine in c#. For the most part it is done and works quite well. One of the features of my lexer is that it allows any user to input their own regular expressions. This ...

regex for four-digit numbers (or "default")

I need a regex for four-digit numbers separated by comma ("default" can also be a value). Examples: 6755 3452,8767,9865,8766,3454 7678,9876 1234,9867,6876,9865 default Note: "default" ...

热门标签