I'm trying to replace any group of two or more periods with just a single period. I suspect the + operator is involved, but I've had nothing but sorrow trying to make the expression using that... So I thought as an experiment I would try to replace just 3 periods with one period. The nonsense below is what I came up with, and of course it doesn't work.
OutNameNoExt:= RegExReplace(OutNameNoExt,"\.\.\." , ".")
Or even better, can I alter this existing expression
OutNameNoExt:= RegExReplace(OutNameNoExt,"[^a-zA-Z0=9_-]" , ".")
so that it never produces more than one period in a row?
Help?
OutNameNoExt:= RegExReplace(OutNameNoExt,"\.{2,}" , ".")
Or, if the {n,m}
(i.e., at least n
, but no more than m
times) syntax is not allowed, you can use the following instead:
OutNameNoExt:= RegExReplace(OutNameNoExt,"\.\.+" , ".")
Alternatively, you can also change the existing expression to the following so that it doesn't produce more than one period in a row:
OutNameNoExt:= RegExReplace(OutNameNoExt,"[^a-zA-Z0=9_-]+" , ".")
For Java, the following regex is working to replace multiple dots with single dot:
String str = "-.-..-...-.-.--..-k....k...k..k.k-.-";
str.replaceAll("\\.\\.+", ".")
Output:
-.-.-.-.-.--.-k.k.k.k.k-.-
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With