开发者

Find and Replace in VS 2008/2010

I'm just trying to remove spaces from some line:

"(jan | feb | mar | apr | may | jun | jul | aug | sep | oct | nov | dec)\.(\s+),(\s+)(\d{4})"  

in my solution and try to do that with find and replace and somewhat don't know how to enter space character in this dialog box. And as I started with so开发者_运维知识库me regx what is the difference between:

"(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)\.(\s+),(\s+)(\d{4})"

and

    "(jan | feb | mar | apr | may | jun | jul | aug | sep | oct | nov | dec)\.(\s+),(\s+)(\d{4})"

regex wise? Thank you for any help.


In order to match both with and without the spaces use [ ]* to include 0 or more space characters

"(jan[ ]*|feb[ ]*|mar[ ]*|apr[ ]*|may[ ]*|jun[ ]*|jul[ ]*|aug[ ]*|sep[ ]*|oct[ ]*|nov[ ]*|dec[ ]*)\.(\s+),(\s+)(\d{4})"


If you put the spaces in, it will require space characters to be there (except when you can enable the "extended" regex syntax).


The second will search for those terms, including spaces. They mean something in regular expressions. It's not whitespace-insensitive. This can be a good or bad thing, depending on how you look at it.

Bottom line: if you want to match spaces, insert spaces. Otherwise, don't.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜