开发者

Regex Replace: Match hypen not preceded by slash

How can i replace Hypen's inside a string, but ignore hypens preceded by a slash eg: "Just-Testing-A-String-\--But i want to leave this hyp开发者_运维技巧en"


If you want to keep only one hyphen that follows the \, then you can use regex

(?<!\\)-

UPDATE: Actually I don't believe that it is possible to create such a rexeg, because in this case you would have to do two replacements: one is for

'-' to ' ' 

and another one is for

'\-' to '-', 

so you need to run two replacements. The only thing I can think of is if you OK with replacing '\' with ' ' also. Then you can use the following regex

((?<!\\)-)|(\\(?=-))


Try something like this:

regex ([^\\])-

replace with $1YOURSTRING


What language are you using? I would go about this in different ways depending on the language being used.

The backslash in your example is actually creating an invalid escape character, "-" will throw an error in most languages. Could you mean a foreword slash, "/"?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜