开发者

regex for not matching

I have 开发者_StackOverflow中文版several strings like this

+My_name
My_other_name
+Someone
Otherone

Whats the regex to write to get me all strings that do not begin with the + symbol

I need the result to include

My_other_name
OtherOne


The simplest is probably:

^[^+].*

Working example: http://rubular.com/r/zzNeuvqKFB

You can drop the .* if you grep the file anyway.
Of course, all programming languages should have a better way of getting these lines. Even grep has the -v flag, to negate the pattern.


Try this:

^[^\+].+$
  1. ^ = Anchor beginning of line
  2. [^\+] = exclude lines beginning with the plus, and is escaped with a slash so not to confuse the regex.
  3. . = any character
    • = repeat any number of times
  4. $ = Anchor end of line.


Depends a bit on what program you are using, but something like ^[^+]+.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜