scala使用正则判断字符串是不是数字
答案:3 悬赏:80 手机版
解决时间 2021-11-12 02:58
- 提问者网友:谁的错
- 2021-11-11 18:31
scala使用正则判断字符串是不是数字
最佳答案
- 五星知识达人网友:罪歌
- 2021-11-11 19:45
要写一个匹配各类计数法的正则表达式比较麻烦,我这里只是一个最简单的整数匹配正则式
def isIntByRegex(s : String) = {
val pattern = """^(d+)$""".r
s match {
case pattern(_*) => true
case _ => false
}
}
isIntByRegex("123")
isIntByRegex("a123")
isIntByRegex("123z")
isIntByRegex("12m3")
def isIntByRegex(s : String) = {
val pattern = """^(d+)$""".r
s match {
case pattern(_*) => true
case _ => false
}
}
isIntByRegex("123")
isIntByRegex("a123")
isIntByRegex("123z")
isIntByRegex("12m3")
全部回答
- 1楼网友:佘樂
- 2021-11-11 21:07
要写一个匹配各类计数法的正则表达式比较麻烦,我这里只是一个最简单的整数匹配正则式
1234567891011def isIntByRegex(s : String) = { val pattern = """^(\d+)$""".r s match { case pattern(_*) => true case _ => false }}isIntByRegex("123")isIntByRegex("a123")isIntByRegex("123z")isIntByRegex("12m3")
1234567891011def isIntByRegex(s : String) = { val pattern = """^(\d+)$""".r s match { case pattern(_*) => true case _ => false }}isIntByRegex("123")isIntByRegex("a123")isIntByRegex("123z")isIntByRegex("12m3")
- 2楼网友:千杯敬自由
- 2021-11-11 20:32
要写一个匹配各类计数法的正则表达式比较麻烦,我这里只是一个最简单的整数匹配正则式
1234567891011def isIntByRegex(s : String) = { val pattern = """^(\d+)$""".r s match { case pattern(_*) => true case _ => false }}isIntByRegex("123")isIntByRegex("a123")isIntByRegex("123z")isIntByRegex("12m3")
1234567891011def isIntByRegex(s : String) = { val pattern = """^(\d+)$""".r s match { case pattern(_*) => true case _ => false }}isIntByRegex("123")isIntByRegex("a123")isIntByRegex("123z")isIntByRegex("12m3")
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯