此语法是什么意思JAVASCRIPT

时间:2018-08-24 11:33:09

标签: javascript regex

偶然发现该库he时,我正在浏览一些开源代码。

在用javascript编写的源代码中,它具有如下语句:

#include<stdio.h>
typedef int status;

typedef struct
{
  status (*ServiceFunc)();
}studentStruct;


status func1()
{
  printf("studenti\n");
  return 0;
}

int main()
{
 studentStruct student[10];
 student[0].ServiceFunc = &func1;

status st = (*student[0].ServiceFunc)();

return 0;
}

我不知道这意味着什么。也尝试过使用Google搜索。

这不是标准的正则表达式。该脚本不尝试匹配regexInvalidRawCodePoint

2 个答案:

答案 0 :(得分:3)

  • regexInvalidRawCodePoint是一个变量
  • /<%= regexInvalidRawCodePoints %>/是一个正则表达式(无选项)

<%=和%>不是Javascript。它们是在评估JavaScript之前进行预处理时将regexInvalidRawCodePoints替换为regexInvalidRawCodePoints值的标记。

因此regexInvalidRawCodePoint在经过预处理后将用作REGEX,并且该regex将分配给变量regexInvalidRawCodePoint

答案 1 :(得分:3)

private void createHeaderRow(String value, Row row, XSSFWorkbook wb, Context context, Logger logger) { try { logger.logInfo("header string is " + value); XSSFCellStyle style = wb.createCellStyle(); Font font = wb.createFont(); font.setBold(true); style.setFont(font); style.setFillForegroundColor(HSSFColor.YELLOW.index); style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); String[] arr = value.split("\\$"); for (int i = 0; i < arr.length; i++) { Cell cell = row.createCell(i); cell.setCellValue(arr[i]); String comment = addHeaderComment(arr[i], context, logger); Drawing drawing = cell.getSheet().createDrawingPatriarch(); CreationHelper factory = wb.getCreationHelper(); ClientAnchor anchor = factory.createClientAnchor(); anchor.setCol1(i); anchor.setCol2(i + 3); anchor.setRow1(row.getRowNum()); anchor.setRow2(row.getRowNum() + 4); Comment ocomment = drawing.createCellComment(anchor); ocomment.setString(factory.createRichTextString(comment)); ocomment.setAuthor(context.getCurrentUser().getUserName()); cell.setCellComment(ocomment); cell.setCellStyle(style); } } catch (Exception e) { logger.logError("Exception occurred in createHeaderRow method...", e); } } 中,您有一个构建脚本:

package.json

此构建脚本将从"build": "grunt build"文件中创建he.js文件。

在构建过程中,该行:

src/he.js

将成为

var regexInvalidRawCodePoint = /<%= regexInvalidRawCodePoints %>/;

负责任的grunt构建任务是使用脚本var regexInvalidRawCodePoint = /[\0-\x08\x0B\x0E-\x1F\x7F-\x9F\uFDD0-\uFDEF\uFFFE\uFFFF]|[\uD83F\uD87F\uD8BF\uD8FF\uD93F\uD97F\uD9BF\uD9FF\uDA3F\uDA7F\uDABF\uDAFF\uDB3F\uDB7F\uDBBF\uDBFF][\uDFFE\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/; 的{​​{1}}。该脚本包含:

template

./scripts/export-data.js是一个占位符,将替换为'regexInvalidRawCodePoints': require('./invalid-code-points-regex.js'), 的内容

这不是JavaScript特有的,而是由例如模板语言。