JavaScript 正则表达式 Xeger

码农软件 · 软件分类 · 正则表达式工具 · 2019-10-09 06:59:46

软件介绍

Xeger 是更富有表现力的 JavaScript 正则表达式,Xeger 发音为 "zeeger"。

使用:

var xeger = require('xeger');
/* Parsing a URL. Getting the schema, host, path, and url params */
/* Instead of this */
var boringRegex= /(https?)\:\/\/([^\/]+)(.+)\?(.*)/;
/* Write this! */
var coolRegex = xeger(function (x) {
  /* schema */
  x.group(function (x) {
    x.literal('http');
    x.literal('s', { optional: true });
  });
  x.literal('://');
  /* host */
  x.group(function (x) {
    x.not('/', { multiple: true });
  });
  /* path */
  x.group(function (x) {
    x.any({ multiple: true });
  });
  x.literal('?');
  /* query params */
  x.group(function (x) {
    x.any({ multiple: true, optional: true });
  });
});
var matched = coolRegex.exec('https://www.google.com/search?q=my_search');

匹配:

[ 'https://www.google.com/search?q=my_search',
  'https',          /* schema       */
  'www.google.com', /* host         */
  '/search',        /* path         */
  'q=my_search',    /* query params */
  index: 0,
  input: 'https://www.google.com/search?q=my_search' ]


本文地址:https://codercto.com/soft/d/16352.html

热点

热点

【美】马克•舍费尔(Mark Shaefer) / 曲秋晨 / 中国人民大学出版社 / 2017-1 / 49.00

你是不是常常困惑: 我创作内容,利用社交媒体,并紧跟每一次数字营销的创新和新平台的运作,可为什么我的业务和影响力没有明显起色? 2015年至2020年间,网络信息量将增长五到十倍,信息极度过剩。如何让你的内容脱颖而出?《热点》由全球顶尖营销专家马克•舍费尔所著,详尽披露如何收获核心粉丝、形成社会认同、引爆热点,进而成功塑造伟大的企业和个人品牌。一起来看看 《热点》 这本书的介绍吧!

在线进制转换器
在线进制转换器

各进制数互转换器

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

随机密码生成器
随机密码生成器

多种字符组合密码