程序设计

专业和发烧友程序员的问答

26
使用JavaScript验证电话号码
我在某些网站上找到了此代码,并且效果很好。它验证电话号码是以下格式之一: (123)456-7890或123-456-7890 问题是我的客户(我不知道为什么,也许是客户的东西)想要添加另一种格式,即连续十个数字,如下所示:1234567890。 我正在使用这个正则表达式, /^(\()?\d{3}(\))?(-|\s)?\d{3}(-|\s)\d{4}$/ 如何添加它还可以验证另一种格式?我对正则表达式不好。
143 javascript  regex 


12
可以使用linux cat命令将文本写入文件吗?
是这样的: cat "Some text here." > myfile.txt 可能?这样,的内容myfile.txt现在将被覆盖为: Some text here. 这对我不起作用,但也不会引发任何错误。 对cat基于解决方案的内容特别感兴趣(不是vim / vi / emacs等)。在线显示的所有示例均cat与文件输入一起使用,而不是原始文本。
143 linux  cat 




18
使用反射获取Java中通用参数的类型
是否可以获取通用参数的类型? 一个例子: public final class Voodoo { public static void chill(List<?> aListWithTypeSpiderMan) { // Here I'd like to get the Class-Object 'SpiderMan' Class typeOfTheList = ???; } public static void main(String... args) { chill(new ArrayList<SpiderMan>()); } }


19
无法推送到Bitbucket上的Git存储库
我创建了一个新的存储库,但遇到一个奇怪的错误。我以前在Bitbucket上使用过Git,但是我只是重新格式化了,现在似乎无法让Git正常工作。提交后,我必须将电子邮件和名称添加到全局变量,但随后提交就可以了。 当我尝试使用命令 git push origin master 它不起作用。我收到此消息: $ git push origin master Permission denied (publickey). fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. 我在这里茫然。我与之共享此存储库的朋友可以很好地访问它并将其推送到正确的位置,但是我似乎无法使其正常工作。
143 git  bitbucket  git-bash 


3
向ggplot2线图添加图例
我对ggplot2中的图例有疑问。我设法在同一张图中绘制三条线,并希望使用所用的三种颜色添加图例。这是使用的代码 library(ggplot2) require(RCurl) link<-getURL("https://dl.dropbox.com/s/ds5zp9jonznpuwb/dat.txt") datos<- read.csv(textConnection(link),header=TRUE,sep=";") datos$fecha <- as.POSIXct(datos[,1], format="%d/%m/%Y") temp = ggplot(data=datos,aes(x=fecha, y=TempMax,colour="1")) + geom_line(colour="red") + opts(title="TITULO") + ylab("Temperatura (C)") + xlab(" ") + scale_y_continuous(limits = c(-10,40)) + geom_line(aes(x=fecha, y=TempMedia,colour="2"),colour="green") + geom_line(aes(x=fecha, y=TempMin,colour="2"),colour="blue") + scale_colour_manual(values=c("red","green","blue")) temp 和输出 我想添加一个图例,其中使用了三种颜色和变量名称(TempMax,TempMedia和TempMin)。我努力了 scale_colour_manual 但找不到确切的方法。 不幸的是,原始数据已从链接站点中删除,无法恢复。但是它们来自具有这种格式的气象数据文件 "date","Tmax","Tmin","Tmed","Precip.diaria","Wmax","Wmed" 2000-07-31 00:00:00,-1.7,-1.7,-1.7,-99.9,20.4,20.4 2000-08-01 00:00:00,22.9,19,21.11,-99.9,6.3,2.83 2000-08-03 00:00:00,24.8,12.3,19.23,-99.9,6.8,3.87 2000-08-04 …
143 r  ggplot2  legend  r-faq 

3
Jetty和Netty有什么区别?
Jetty和Netty之间的主要区别是什么? Netty是Jboss的一部分,但是它是默认的Web服务器容器吗? Netty是否支持Servlets 3.0?
143 jetty  netty 

7
Linux环境变量名称中允许使用的字符
Linux环境变量名称中允许使用哪些字符?我对手册页和网络的粗略搜索只产生了有关如何使用变量的信息,但没有产生允许使用的名称。 我有一个Java程序,它需要一个包含点的已定义环境变量,例如com.example.fancyproperty。使用Windows,我可以设置该变量,但是我没有在Linux中设置它的运气(在SuSE和Ubuntu中尝试过)。甚至允许使用该变量名吗?

9
有没有办法从持有类名的字符串中实例化对象?
我有一个文件:Base.h class Base; class DerivedA : public Base; class DerivedB : public Base; /*etc...*/ 和另一个文件:BaseFactory.h #include "Base.h" class BaseFactory { public: BaseFactory(const string &sClassName){msClassName = sClassName;}; Base * Create() { if(msClassName == "DerivedA") { return new DerivedA(); } else if(msClassName == "DerivedB") { return new DerivedB(); } else if(/*etc...*/) { …

4
根据正则表达式分割字符串
我有表格形式的命令输出。我正在从结果文件中解析此输出,并将其存储在字符串中。一行中的每个元素都由一个或多个空格字符分隔,因此我正在使用正则表达式来匹配1个或多个空格并将其拆分。但是,每个元素之间都会插入一个空格: >>> str1="a b c d" # spaces are irregular >>> str1 'a b c d' >>> str2=re.split("( )+", str1) >>> str2 ['a', ' ', 'b', ' ', 'c', ' ', 'd'] # 1 space element between!!! 有一个更好的方法吗? 每次拆分后都会str2添加到列表中。
143 python  regex 

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.