0

I have following regex in perl for replacing all continuous non-whitespace characters

perl -p -i.bak -e 's/^set gamma=\S*/set gamma=GAMMA/' tmp;

If the tmp file contains set gamma=sdjfskdf; #comment then I want to preserve the semicolon along with the comment. But using \S* deletes sdjfskdf;.

What change should I make to the regex?

4

2 回答 2

3

Try s/^set gamma=[^;\s]*/set gamma=GAMMA/

于 2013-03-30T05:33:22.103 回答
2

In your expression you can replace \S* with [^\s;]*, which doesn't match spaces nor ;.

于 2013-03-30T05:33:14.160 回答