Regex: match all hyphens and replace by spaces for words that contains only letters AND that are NOT inside...












1















This regex: b([A-z*]+)-(?=[A-z*]+b)



with this replacement: $1 



Applied on:



Jean-Pierre bought "blue-green-red" product-2345 and other blue-red stuff.


Gives me:



Jean Pierre bought "blue green red" product-2345 and other blue red stuff.


While I want:



Jean Pierre bought "blue-green-red" product-2345 and other blue red stuff.


https://regex101.com/r/SJzAaP/1



EDIT:



I am using Clojure (Java)



EDIT 2:



yellow-black-white -> yellow black white



product_a-b -> product_a-b



EDIT 3: Accepted answer translated in Clojure



(clojure.string/replace
"Jean-Pierre bought "blue-green-red" product-2345 and other blue-red-green stuff yellow-black-white product_a-b"
#"("[^"]*")|b([a-zA-Z]+)-(?=[a-zA-Z]+b)"
(fn [[s1 s2 s3]] (if s2 s1 (str s3 " "))))

;;=> "Jean Pierre bought "blue-green-red" product-2345 and other blue red green stuff yellow black white product_a-b"









share|improve this question

























  • Your regex does not match that string.

    – Wiktor Stribiżew
    Nov 23 '18 at 20:29











  • This is actually my best shot: regex101.com/r/SJzAaP/1 Just edited question. Thanks!

    – leontalbot
    Nov 23 '18 at 20:33













  • Ok, just FYI: [A-z] does not only match letters. What is your regex flavor?

    – Wiktor Stribiżew
    Nov 23 '18 at 20:34













  • Thanks again, edited the title.

    – leontalbot
    Nov 23 '18 at 20:36






  • 1





    Use "[^"]*"(*SKIP)(?!)|b[a-zA-Z]+K-(?=[a-zA-Z]+b) and replace with a space. See the regex demo.

    – Wiktor Stribiżew
    Nov 23 '18 at 20:40


















1















This regex: b([A-z*]+)-(?=[A-z*]+b)



with this replacement: $1 



Applied on:



Jean-Pierre bought "blue-green-red" product-2345 and other blue-red stuff.


Gives me:



Jean Pierre bought "blue green red" product-2345 and other blue red stuff.


While I want:



Jean Pierre bought "blue-green-red" product-2345 and other blue red stuff.


https://regex101.com/r/SJzAaP/1



EDIT:



I am using Clojure (Java)



EDIT 2:



yellow-black-white -> yellow black white



product_a-b -> product_a-b



EDIT 3: Accepted answer translated in Clojure



(clojure.string/replace
"Jean-Pierre bought "blue-green-red" product-2345 and other blue-red-green stuff yellow-black-white product_a-b"
#"("[^"]*")|b([a-zA-Z]+)-(?=[a-zA-Z]+b)"
(fn [[s1 s2 s3]] (if s2 s1 (str s3 " "))))

;;=> "Jean Pierre bought "blue-green-red" product-2345 and other blue red green stuff yellow black white product_a-b"









share|improve this question

























  • Your regex does not match that string.

    – Wiktor Stribiżew
    Nov 23 '18 at 20:29











  • This is actually my best shot: regex101.com/r/SJzAaP/1 Just edited question. Thanks!

    – leontalbot
    Nov 23 '18 at 20:33













  • Ok, just FYI: [A-z] does not only match letters. What is your regex flavor?

    – Wiktor Stribiżew
    Nov 23 '18 at 20:34













  • Thanks again, edited the title.

    – leontalbot
    Nov 23 '18 at 20:36






  • 1





    Use "[^"]*"(*SKIP)(?!)|b[a-zA-Z]+K-(?=[a-zA-Z]+b) and replace with a space. See the regex demo.

    – Wiktor Stribiżew
    Nov 23 '18 at 20:40
















1












1








1








This regex: b([A-z*]+)-(?=[A-z*]+b)



with this replacement: $1 



Applied on:



Jean-Pierre bought "blue-green-red" product-2345 and other blue-red stuff.


Gives me:



Jean Pierre bought "blue green red" product-2345 and other blue red stuff.


While I want:



Jean Pierre bought "blue-green-red" product-2345 and other blue red stuff.


https://regex101.com/r/SJzAaP/1



EDIT:



I am using Clojure (Java)



EDIT 2:



yellow-black-white -> yellow black white



product_a-b -> product_a-b



EDIT 3: Accepted answer translated in Clojure



(clojure.string/replace
"Jean-Pierre bought "blue-green-red" product-2345 and other blue-red-green stuff yellow-black-white product_a-b"
#"("[^"]*")|b([a-zA-Z]+)-(?=[a-zA-Z]+b)"
(fn [[s1 s2 s3]] (if s2 s1 (str s3 " "))))

;;=> "Jean Pierre bought "blue-green-red" product-2345 and other blue red green stuff yellow black white product_a-b"









share|improve this question
















This regex: b([A-z*]+)-(?=[A-z*]+b)



with this replacement: $1 



Applied on:



Jean-Pierre bought "blue-green-red" product-2345 and other blue-red stuff.


Gives me:



Jean Pierre bought "blue green red" product-2345 and other blue red stuff.


While I want:



Jean Pierre bought "blue-green-red" product-2345 and other blue red stuff.


https://regex101.com/r/SJzAaP/1



EDIT:



I am using Clojure (Java)



EDIT 2:



yellow-black-white -> yellow black white



product_a-b -> product_a-b



EDIT 3: Accepted answer translated in Clojure



(clojure.string/replace
"Jean-Pierre bought "blue-green-red" product-2345 and other blue-red-green stuff yellow-black-white product_a-b"
#"("[^"]*")|b([a-zA-Z]+)-(?=[a-zA-Z]+b)"
(fn [[s1 s2 s3]] (if s2 s1 (str s3 " "))))

;;=> "Jean Pierre bought "blue-green-red" product-2345 and other blue red green stuff yellow black white product_a-b"






java regex clojure






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 24 '18 at 1:54







leontalbot

















asked Nov 23 '18 at 20:23









leontalbotleontalbot

1,6141326




1,6141326













  • Your regex does not match that string.

    – Wiktor Stribiżew
    Nov 23 '18 at 20:29











  • This is actually my best shot: regex101.com/r/SJzAaP/1 Just edited question. Thanks!

    – leontalbot
    Nov 23 '18 at 20:33













  • Ok, just FYI: [A-z] does not only match letters. What is your regex flavor?

    – Wiktor Stribiżew
    Nov 23 '18 at 20:34













  • Thanks again, edited the title.

    – leontalbot
    Nov 23 '18 at 20:36






  • 1





    Use "[^"]*"(*SKIP)(?!)|b[a-zA-Z]+K-(?=[a-zA-Z]+b) and replace with a space. See the regex demo.

    – Wiktor Stribiżew
    Nov 23 '18 at 20:40





















  • Your regex does not match that string.

    – Wiktor Stribiżew
    Nov 23 '18 at 20:29











  • This is actually my best shot: regex101.com/r/SJzAaP/1 Just edited question. Thanks!

    – leontalbot
    Nov 23 '18 at 20:33













  • Ok, just FYI: [A-z] does not only match letters. What is your regex flavor?

    – Wiktor Stribiżew
    Nov 23 '18 at 20:34













  • Thanks again, edited the title.

    – leontalbot
    Nov 23 '18 at 20:36






  • 1





    Use "[^"]*"(*SKIP)(?!)|b[a-zA-Z]+K-(?=[a-zA-Z]+b) and replace with a space. See the regex demo.

    – Wiktor Stribiżew
    Nov 23 '18 at 20:40



















Your regex does not match that string.

– Wiktor Stribiżew
Nov 23 '18 at 20:29





Your regex does not match that string.

– Wiktor Stribiżew
Nov 23 '18 at 20:29













This is actually my best shot: regex101.com/r/SJzAaP/1 Just edited question. Thanks!

– leontalbot
Nov 23 '18 at 20:33







This is actually my best shot: regex101.com/r/SJzAaP/1 Just edited question. Thanks!

– leontalbot
Nov 23 '18 at 20:33















Ok, just FYI: [A-z] does not only match letters. What is your regex flavor?

– Wiktor Stribiżew
Nov 23 '18 at 20:34







Ok, just FYI: [A-z] does not only match letters. What is your regex flavor?

– Wiktor Stribiżew
Nov 23 '18 at 20:34















Thanks again, edited the title.

– leontalbot
Nov 23 '18 at 20:36





Thanks again, edited the title.

– leontalbot
Nov 23 '18 at 20:36




1




1





Use "[^"]*"(*SKIP)(?!)|b[a-zA-Z]+K-(?=[a-zA-Z]+b) and replace with a space. See the regex demo.

– Wiktor Stribiżew
Nov 23 '18 at 20:40







Use "[^"]*"(*SKIP)(?!)|b[a-zA-Z]+K-(?=[a-zA-Z]+b) and replace with a space. See the regex demo.

– Wiktor Stribiżew
Nov 23 '18 at 20:40














3 Answers
3






active

oldest

votes


















1














In Java, you may use something like



String s = "Jean-Pierre bought "blue-green-red" product-2345 and other blue-red stuff. yellow-black-white. product_a-b";
StringBuffer result = new StringBuffer();
Matcher m = Pattern.compile("("[^"]*")|\b([a-zA-Z]+)-(?=[a-zA-Z]+\b)").matcher(s);
while (m.find()) {
if (m.group(1) != null) {
m.appendReplacement(result, m.group(0));
} else {
m.appendReplacement(result, m.group(2) + " ");
}
}
m.appendTail(result);
System.out.println(result.toString());
// => Jean Pierre bought "blue-green-red" product-2345 and other blue red stuff. yellow black white. product_a-b


See the Java demo.



The regex is



("[^"]*")|b([a-zA-Z]+)-(?=[a-zA-Z]+b)


Details





  • ("[^"]*") - Group 1: ", 0+ chars other than " and "


  • | - or


  • b - word boundary
    -([a-zA-Z]+) - Group 2: 1+ letters (may be replaced with (p{L}+) to match any letter)


  • - - a hyphen


  • (?=[a-zA-Z]+b) - a positive lookahead that, immediately to the right of the current location, requires 1+ letters and a word boundary.


If Group 1 matches (if (m.group(1) != null)) you just paste the match back into the result. If not, paste back Group 2 value and a space.



Adding clojure code here from the question, too, for better visibility:



(def s "Jean-Pierre bought "blue-green-red" product-2345 and other blue-red stuff. yellow-black-white. product_a-b"

(defn append [[g1 g2 g3]] (if g2 g1 (str g3 " ")))

(clojure.string/replace s #"("[^"]*")|b([a-zA-Z]+)-(?=[a-zA-Z]+b)" append)

;;=> "Jean Pierre bought "blue-green-red" product-2345 and other blue red stuff. yellow black white. product_a-b"





share|improve this answer





















  • 1





    Thanks! Works fine! Translated your answer in Clojure in my last question edit.

    – leontalbot
    Nov 24 '18 at 1:54











  • Made small edition to clojure code. Thanks again!

    – leontalbot
    Nov 24 '18 at 15:02





















0














This should work if you don't need to handle too complex cases:



(?: |^)w+(-)(?![0-9])w+



This matches any instance of word(hyphen)word that has a space at the beginning or is the beginning of the line (so, the stuff in the quotes will not match because there would be a quote before it, not a space or the beginning of the line).



Let me know if this doesn't work for you. Live demo.






share|improve this answer
























  • Hmm, that's working except wouldn't work for other blue-red-green-yellow stuff which I want to cover too and I don't want this removed product_a-b

    – leontalbot
    Nov 23 '18 at 20:52





















0














Try this one



(".*?")|((?<group>b([A-z*]+))-)


with substitution



${group} $1


You can test it here






share|improve this answer
























  • bought  "blue-green-red" product 2345 should be bought "blue-green-red" product-2345

    – leontalbot
    Nov 23 '18 at 21:07













Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53452565%2fregex-match-all-hyphens-and-replace-by-spaces-for-words-that-contains-only-lett%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























3 Answers
3






active

oldest

votes








3 Answers
3






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














In Java, you may use something like



String s = "Jean-Pierre bought "blue-green-red" product-2345 and other blue-red stuff. yellow-black-white. product_a-b";
StringBuffer result = new StringBuffer();
Matcher m = Pattern.compile("("[^"]*")|\b([a-zA-Z]+)-(?=[a-zA-Z]+\b)").matcher(s);
while (m.find()) {
if (m.group(1) != null) {
m.appendReplacement(result, m.group(0));
} else {
m.appendReplacement(result, m.group(2) + " ");
}
}
m.appendTail(result);
System.out.println(result.toString());
// => Jean Pierre bought "blue-green-red" product-2345 and other blue red stuff. yellow black white. product_a-b


See the Java demo.



The regex is



("[^"]*")|b([a-zA-Z]+)-(?=[a-zA-Z]+b)


Details





  • ("[^"]*") - Group 1: ", 0+ chars other than " and "


  • | - or


  • b - word boundary
    -([a-zA-Z]+) - Group 2: 1+ letters (may be replaced with (p{L}+) to match any letter)


  • - - a hyphen


  • (?=[a-zA-Z]+b) - a positive lookahead that, immediately to the right of the current location, requires 1+ letters and a word boundary.


If Group 1 matches (if (m.group(1) != null)) you just paste the match back into the result. If not, paste back Group 2 value and a space.



Adding clojure code here from the question, too, for better visibility:



(def s "Jean-Pierre bought "blue-green-red" product-2345 and other blue-red stuff. yellow-black-white. product_a-b"

(defn append [[g1 g2 g3]] (if g2 g1 (str g3 " ")))

(clojure.string/replace s #"("[^"]*")|b([a-zA-Z]+)-(?=[a-zA-Z]+b)" append)

;;=> "Jean Pierre bought "blue-green-red" product-2345 and other blue red stuff. yellow black white. product_a-b"





share|improve this answer





















  • 1





    Thanks! Works fine! Translated your answer in Clojure in my last question edit.

    – leontalbot
    Nov 24 '18 at 1:54











  • Made small edition to clojure code. Thanks again!

    – leontalbot
    Nov 24 '18 at 15:02


















1














In Java, you may use something like



String s = "Jean-Pierre bought "blue-green-red" product-2345 and other blue-red stuff. yellow-black-white. product_a-b";
StringBuffer result = new StringBuffer();
Matcher m = Pattern.compile("("[^"]*")|\b([a-zA-Z]+)-(?=[a-zA-Z]+\b)").matcher(s);
while (m.find()) {
if (m.group(1) != null) {
m.appendReplacement(result, m.group(0));
} else {
m.appendReplacement(result, m.group(2) + " ");
}
}
m.appendTail(result);
System.out.println(result.toString());
// => Jean Pierre bought "blue-green-red" product-2345 and other blue red stuff. yellow black white. product_a-b


See the Java demo.



The regex is



("[^"]*")|b([a-zA-Z]+)-(?=[a-zA-Z]+b)


Details





  • ("[^"]*") - Group 1: ", 0+ chars other than " and "


  • | - or


  • b - word boundary
    -([a-zA-Z]+) - Group 2: 1+ letters (may be replaced with (p{L}+) to match any letter)


  • - - a hyphen


  • (?=[a-zA-Z]+b) - a positive lookahead that, immediately to the right of the current location, requires 1+ letters and a word boundary.


If Group 1 matches (if (m.group(1) != null)) you just paste the match back into the result. If not, paste back Group 2 value and a space.



Adding clojure code here from the question, too, for better visibility:



(def s "Jean-Pierre bought "blue-green-red" product-2345 and other blue-red stuff. yellow-black-white. product_a-b"

(defn append [[g1 g2 g3]] (if g2 g1 (str g3 " ")))

(clojure.string/replace s #"("[^"]*")|b([a-zA-Z]+)-(?=[a-zA-Z]+b)" append)

;;=> "Jean Pierre bought "blue-green-red" product-2345 and other blue red stuff. yellow black white. product_a-b"





share|improve this answer





















  • 1





    Thanks! Works fine! Translated your answer in Clojure in my last question edit.

    – leontalbot
    Nov 24 '18 at 1:54











  • Made small edition to clojure code. Thanks again!

    – leontalbot
    Nov 24 '18 at 15:02
















1












1








1







In Java, you may use something like



String s = "Jean-Pierre bought "blue-green-red" product-2345 and other blue-red stuff. yellow-black-white. product_a-b";
StringBuffer result = new StringBuffer();
Matcher m = Pattern.compile("("[^"]*")|\b([a-zA-Z]+)-(?=[a-zA-Z]+\b)").matcher(s);
while (m.find()) {
if (m.group(1) != null) {
m.appendReplacement(result, m.group(0));
} else {
m.appendReplacement(result, m.group(2) + " ");
}
}
m.appendTail(result);
System.out.println(result.toString());
// => Jean Pierre bought "blue-green-red" product-2345 and other blue red stuff. yellow black white. product_a-b


See the Java demo.



The regex is



("[^"]*")|b([a-zA-Z]+)-(?=[a-zA-Z]+b)


Details





  • ("[^"]*") - Group 1: ", 0+ chars other than " and "


  • | - or


  • b - word boundary
    -([a-zA-Z]+) - Group 2: 1+ letters (may be replaced with (p{L}+) to match any letter)


  • - - a hyphen


  • (?=[a-zA-Z]+b) - a positive lookahead that, immediately to the right of the current location, requires 1+ letters and a word boundary.


If Group 1 matches (if (m.group(1) != null)) you just paste the match back into the result. If not, paste back Group 2 value and a space.



Adding clojure code here from the question, too, for better visibility:



(def s "Jean-Pierre bought "blue-green-red" product-2345 and other blue-red stuff. yellow-black-white. product_a-b"

(defn append [[g1 g2 g3]] (if g2 g1 (str g3 " ")))

(clojure.string/replace s #"("[^"]*")|b([a-zA-Z]+)-(?=[a-zA-Z]+b)" append)

;;=> "Jean Pierre bought "blue-green-red" product-2345 and other blue red stuff. yellow black white. product_a-b"





share|improve this answer















In Java, you may use something like



String s = "Jean-Pierre bought "blue-green-red" product-2345 and other blue-red stuff. yellow-black-white. product_a-b";
StringBuffer result = new StringBuffer();
Matcher m = Pattern.compile("("[^"]*")|\b([a-zA-Z]+)-(?=[a-zA-Z]+\b)").matcher(s);
while (m.find()) {
if (m.group(1) != null) {
m.appendReplacement(result, m.group(0));
} else {
m.appendReplacement(result, m.group(2) + " ");
}
}
m.appendTail(result);
System.out.println(result.toString());
// => Jean Pierre bought "blue-green-red" product-2345 and other blue red stuff. yellow black white. product_a-b


See the Java demo.



The regex is



("[^"]*")|b([a-zA-Z]+)-(?=[a-zA-Z]+b)


Details





  • ("[^"]*") - Group 1: ", 0+ chars other than " and "


  • | - or


  • b - word boundary
    -([a-zA-Z]+) - Group 2: 1+ letters (may be replaced with (p{L}+) to match any letter)


  • - - a hyphen


  • (?=[a-zA-Z]+b) - a positive lookahead that, immediately to the right of the current location, requires 1+ letters and a word boundary.


If Group 1 matches (if (m.group(1) != null)) you just paste the match back into the result. If not, paste back Group 2 value and a space.



Adding clojure code here from the question, too, for better visibility:



(def s "Jean-Pierre bought "blue-green-red" product-2345 and other blue-red stuff. yellow-black-white. product_a-b"

(defn append [[g1 g2 g3]] (if g2 g1 (str g3 " ")))

(clojure.string/replace s #"("[^"]*")|b([a-zA-Z]+)-(?=[a-zA-Z]+b)" append)

;;=> "Jean Pierre bought "blue-green-red" product-2345 and other blue red stuff. yellow black white. product_a-b"






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 24 '18 at 15:33









leontalbot

1,6141326




1,6141326










answered Nov 23 '18 at 20:55









Wiktor StribiżewWiktor Stribiżew

317k16138220




317k16138220








  • 1





    Thanks! Works fine! Translated your answer in Clojure in my last question edit.

    – leontalbot
    Nov 24 '18 at 1:54











  • Made small edition to clojure code. Thanks again!

    – leontalbot
    Nov 24 '18 at 15:02
















  • 1





    Thanks! Works fine! Translated your answer in Clojure in my last question edit.

    – leontalbot
    Nov 24 '18 at 1:54











  • Made small edition to clojure code. Thanks again!

    – leontalbot
    Nov 24 '18 at 15:02










1




1





Thanks! Works fine! Translated your answer in Clojure in my last question edit.

– leontalbot
Nov 24 '18 at 1:54





Thanks! Works fine! Translated your answer in Clojure in my last question edit.

– leontalbot
Nov 24 '18 at 1:54













Made small edition to clojure code. Thanks again!

– leontalbot
Nov 24 '18 at 15:02







Made small edition to clojure code. Thanks again!

– leontalbot
Nov 24 '18 at 15:02















0














This should work if you don't need to handle too complex cases:



(?: |^)w+(-)(?![0-9])w+



This matches any instance of word(hyphen)word that has a space at the beginning or is the beginning of the line (so, the stuff in the quotes will not match because there would be a quote before it, not a space or the beginning of the line).



Let me know if this doesn't work for you. Live demo.






share|improve this answer
























  • Hmm, that's working except wouldn't work for other blue-red-green-yellow stuff which I want to cover too and I don't want this removed product_a-b

    – leontalbot
    Nov 23 '18 at 20:52


















0














This should work if you don't need to handle too complex cases:



(?: |^)w+(-)(?![0-9])w+



This matches any instance of word(hyphen)word that has a space at the beginning or is the beginning of the line (so, the stuff in the quotes will not match because there would be a quote before it, not a space or the beginning of the line).



Let me know if this doesn't work for you. Live demo.






share|improve this answer
























  • Hmm, that's working except wouldn't work for other blue-red-green-yellow stuff which I want to cover too and I don't want this removed product_a-b

    – leontalbot
    Nov 23 '18 at 20:52
















0












0








0







This should work if you don't need to handle too complex cases:



(?: |^)w+(-)(?![0-9])w+



This matches any instance of word(hyphen)word that has a space at the beginning or is the beginning of the line (so, the stuff in the quotes will not match because there would be a quote before it, not a space or the beginning of the line).



Let me know if this doesn't work for you. Live demo.






share|improve this answer













This should work if you don't need to handle too complex cases:



(?: |^)w+(-)(?![0-9])w+



This matches any instance of word(hyphen)word that has a space at the beginning or is the beginning of the line (so, the stuff in the quotes will not match because there would be a quote before it, not a space or the beginning of the line).



Let me know if this doesn't work for you. Live demo.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 23 '18 at 20:48









connectyourchargerconnectyourcharger

542323




542323













  • Hmm, that's working except wouldn't work for other blue-red-green-yellow stuff which I want to cover too and I don't want this removed product_a-b

    – leontalbot
    Nov 23 '18 at 20:52





















  • Hmm, that's working except wouldn't work for other blue-red-green-yellow stuff which I want to cover too and I don't want this removed product_a-b

    – leontalbot
    Nov 23 '18 at 20:52



















Hmm, that's working except wouldn't work for other blue-red-green-yellow stuff which I want to cover too and I don't want this removed product_a-b

– leontalbot
Nov 23 '18 at 20:52







Hmm, that's working except wouldn't work for other blue-red-green-yellow stuff which I want to cover too and I don't want this removed product_a-b

– leontalbot
Nov 23 '18 at 20:52













0














Try this one



(".*?")|((?<group>b([A-z*]+))-)


with substitution



${group} $1


You can test it here






share|improve this answer
























  • bought  "blue-green-red" product 2345 should be bought "blue-green-red" product-2345

    – leontalbot
    Nov 23 '18 at 21:07


















0














Try this one



(".*?")|((?<group>b([A-z*]+))-)


with substitution



${group} $1


You can test it here






share|improve this answer
























  • bought  "blue-green-red" product 2345 should be bought "blue-green-red" product-2345

    – leontalbot
    Nov 23 '18 at 21:07
















0












0








0







Try this one



(".*?")|((?<group>b([A-z*]+))-)


with substitution



${group} $1


You can test it here






share|improve this answer













Try this one



(".*?")|((?<group>b([A-z*]+))-)


with substitution



${group} $1


You can test it here







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 23 '18 at 21:00









Alfredo A.Alfredo A.

98011633




98011633













  • bought  "blue-green-red" product 2345 should be bought "blue-green-red" product-2345

    – leontalbot
    Nov 23 '18 at 21:07





















  • bought  "blue-green-red" product 2345 should be bought "blue-green-red" product-2345

    – leontalbot
    Nov 23 '18 at 21:07



















bought  "blue-green-red" product 2345 should be bought "blue-green-red" product-2345

– leontalbot
Nov 23 '18 at 21:07







bought  "blue-green-red" product 2345 should be bought "blue-green-red" product-2345

– leontalbot
Nov 23 '18 at 21:07




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53452565%2fregex-match-all-hyphens-and-replace-by-spaces-for-words-that-contains-only-lett%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Wiesbaden

Marschland

Dieringhausen