从数组中添加数字?(adding numbers from array?)
我有:
var str="100px"; var number = str.split("px"); number = number[0]; var km = "100px"; var numberk = km.split("px"); numberk = numberk[0]; var gim = numberk+100; var kim = number+100; var fim = number+numberk; document.write(gim+'<br>'+kim+'<br>'+jim+'<br>');
如果有人能够回答为什么结果像字符串而不是javascript中的数字数字我已经使用了
isNaN();
我会感激不尽isNaN();
将此显示为合法号码的功能。 那么如何解决这个问题呢。谢谢。
i have:
var str="100px"; var number = str.split("px"); number = number[0]; var km = "100px"; var numberk = km.split("px"); numberk = numberk[0]; var gim = numberk+100; var kim = number+100; var fim = number+numberk; document.write(gim+'<br>'+kim+'<br>'+jim+'<br>');
i would be thankfull if someone could me answere why the result are added like string rather than nummerical number in javascript i have used the
isNaN();
function which shows this as a legal number. So how can this problem be solved.thanks.
原文:https://stackoverflow.com/questions/8647122
最满意答案
编辑:
正如大多数其他正则表达式引擎一样, Ruby的Regex实现似乎不支持在一个组上执行多个捕获 。 因此,你必须做两步; 首先在一个字符串中获取所有
@*:*
,然后再分割这些。为了获得所有这些,这应该工作:
(\[([a-zA-Z]+)=([a-zA-Z0-9]+)((?:@[a-zA-Z]+:[a-zA-Z]+)*)\])
Edit:
Ruby's Regex implementation seems not to support multiple captures on one group, as most other regex engines do. Therefore, you'll have to do two steps; first getting all the
@*:*
in one string and then split those.To get all of them, this should work:
(\[([a-zA-Z]+)=([a-zA-Z0-9]+)((?:@[a-zA-Z]+:[a-zA-Z]+)*)\])
相关问答
更多-
TCP/IP模型是一个________。[2023-10-02]
a -
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
编辑: 正如大多数其他正则表达式引擎一样, Ruby的Regex实现似乎不支持在一个组上执行多个捕获 。 因此,你必须做两步; 首先在一个字符串中获取所有@*:* ,然后再分割这些。 为了获得所有这些,这应该工作: (\[([a-zA-Z]+)=([a-zA-Z0-9]+)((?:@[a-zA-Z]+:[a-zA-Z]+)*)\]) Edit: Ruby's Regex implementation seems not to support multiple captures on one group, ...
-
使用Matcher : public static void printMatches(String text, String regex) { Pattern pattern = Pattern.compile(regex); Matcher matcher = pattern.matcher(text); // Check all occurrences while (matcher.find()) { System.out.print("Start in ...
-
尝试以下操作来捕获任何键和值 ^\"[^"]+.*(?:\\")?\"\s*:\s*(?:(\d+)|\"([^"]+.*(?:\\")?)\")$ 例如https://regex101.com/r/KkSiT4/2 如果您只查找myid并使用以下数字: "myid"\s*:\s*"(\d+)" https://regex101.com/r/DTnMRA/1 如果myid的值可以包含任何字符而不仅仅是数字,请使用以下内容: "myid"\s*:\s*"([^"]+.*(?:\\")?)" https: ...
-
在正则表达式中使用逻辑来匹配嵌套模式可能会让你陷入噩梦,正则表达式可能不是正确的工具。 基于你的正则表达式,我可以想出一些改变并使用这个: input{([\s\S]*?)^} 工作演示 它将使用带有}的起始行作为结束分隔符,它可以解决您的特定问题,但正则表达式可能不是您问题的最佳答案。 Having logic in regex to match nested patterns might bring you into a nightmare and regex may not be the right ...
-
这将满足您的需求: \w+$ \w是“单词字符”的元字符,包括字母,数字和下划线。 +表示“一个或多个”,而$表示“行尾”所以你可以用英语将其解释为:“匹配由字母,数字和行尾的下划线字符组成的单词。” 如果你只想要字母,你可以这样做: [a-zA-Z]+$ This will do what you need: \w+$ \w is the metacharacter for "word character", which includes letters, numbers, and undersco ...
-
您需要添加更多组,如下所示: ^BIN:.*?(\d+).*?#:\s+(\d+).*?#:\s+(\d+) 。 我使用#s作为开始寻找跟踪和书籍识别细节的点。 请注意,与*?使用延迟匹配很重要*? 。 这是regex101的更新示例 。 输出: MATCH 1 1. [5-9] `1234` 2. [22-27] `56789` 3. [51-57] `121212` You need to add more groups, like this: ^BIN:.*?(\d+).*?#:\s+(\ ...
-
以下是我可能会解决这个问题,但不使用任何更复杂的正则表达式逻辑。 def findNthLine(n: Int, r: Regex): List[String] = { @tailrec def rec(lines: List[String], acc: List[String]): List[String] = { if (lines.isEmpty) acc else { r.findFirstIn(lines.head) match { ...
-
String的matches(...)方法返回boolean ,而不是String 。 你可以像这样解决它: String str = "<accountName>THOMAS M PINCHBECK</accountName>"+ "<accountName>Hello world</accountName>"+ "<accountName>Quick brown fox</accountName>"; Pattern ...