Skip to content

Instantly share code, notes, and snippets.

@helinjiang
Created July 5, 2018 06:07
Show Gist options
  • Save helinjiang/640b365ed377bef99b8a9c41f7337257 to your computer and use it in GitHub Desktop.
Save helinjiang/640b365ed377bef99b8a9c41f7337257 to your computer and use it in GitHub Desktop.
remove path pre
const path = require('path');
let reg1 = /^\.([^[\\||\/])*[\\||\/]/gi;
let reg2 = /^\.([^[\\||\/])*[\\||\/]/gi;
let windowsPath = '..\\e2e_test\\page_rule\\cases\\basic-ui-check.js';
console.log(windowsPath.match(reg1)); // [ '..\\' ]
console.log(windowsPath.replace(reg2, '')); // e2e_test\page_rule\cases\basic-ui-check.js
console.log('\n=====\n');
let macPath = '../e2e_test/page_rule/cases/basic-ui-check.js';
console.log(macPath.match(reg1)); // [ '../' ]
console.log(macPath.replace(reg2, '')); // e2e_test/page_rule/cases/basic-ui-check.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment