Reputation: 63
How do I return the value I searched for in RegExp and then add my modifier? For example the following RegExpression will search for any word between the comma's.
[^,\s][^\,]*[^,\s]*
The following is my input:
Biscuit, Pudding, Pizza, Beans
However I can't find a way to add a word like "Cheese-" to those words. The expected output would be:
Cheese-Biscuit, Cheese-Pudding, Cheese-Pizza, Cheese-Beans
Upvotes: 1
Views: 128
Reputation: 17272
Update-you have changed to say notepad++. I will leave in case useful to someone else.
Assuming Javascript (since you mention RegExp):
var str = "Biscuit, Pudding, Pizza, Beans";
var patt1 = /[^,\s][^\,]*[^,\s]*/g;
var result = str.replace(patt1,"Cheese-" + "$&");
Output:
Cheese-Biscuit, Cheese-Pudding, Cheese-Pizza, Cheese-Beans
$& inserts the matched substring.
/g does global match - all matched words.
See here for more information.
Upvotes: 1
Reputation: 48751
Do a CTRL+H
in Notepad++, in replace window search mode block, check Regular Expression.
then in Find what field type : ([^,\s][^\,]*[^,\s]*)
and in Replace with field type: Cheese-\1
then replace all, you'll see this result:
Cheese-Biscuit, Cheese-Pudding, Cheese-Pizza, Cheese-Beans
Upvotes: 2