我会使用regex从匹配的字符串中提取特定的字符串。
0000022 DE BERNARDINIS FERNANDO DBRFNN72A03A515E 001468 03-01 1972年12-06-2006年
从上面的段落中,我需要找到日期可用的位置,在此基础上,我需要从匹配的带有单个正则表达式的字符串中提取第二个和第三个单词。
".*\n(\d{2}-\d{2}-\d{4}) (\d{2}-\d{2}-\d{4})" - will result only
"0000022 DE BERNARDINIS FERNANDO DBRFNN72A03A515E 0014
在同时包含数字和字符串的列中,如何仅获得数字的总和?从api中提取数据并将其填充到表中。我有简单的代码来获得和,但是由于数字和字符串的组合,我最终得到了NaN作为结果。
我已尝试检查NaN,但得到的结果为空
getSum(index: number) : number {
let sum = 0;
let i = 0;
if( isNaN(i) == true){
for(let i = 0; i < this.agemenBaisv.length; i++) {
sum += this.agemenBaisv[i][index];
如果需要的话
if <this list has a string in it that matches this rexeg>:
do_stuff()
我这个强大的构造来从列表中提取匹配的字符串:
[m.group(1) for l in my_list for m in [my_regex.search(l)] if m]
...but,这是很难读懂和过火的。我不想要这个名单,我只想知道这样的清单是否会有任何内容。
有没有一种简单的阅读方法可以得到这个答案?
我试图从给定的整数中提取一个单独的数字。从1234开始,我希望将1、2、3、4存储在一个array.The数字中,但每次都不一定相同。我不知道如何初始化相同的数组。
int number = 1234;
int [] a = new int[];
for(int i =0;i<lengthOfNum;i++){
a[i] = digitReturn();
}
我正在尝试使用perl解析将出现在课程目录中的数据,但我正在努力使我的正则表达式正确工作。
以下是几行样本数据:
Course description goes here; There might be more text; 3 hours of lecture, 2 hours of laboratory. Prerequisite: None
Another course description is here; 3 hours of lecture and laboratory. Prerequisite: None
More description; 4 hours of labora