Skip to content

More readable way for creating RegExp. Belong to "Plan J"./可读性更好的正则表达式创建方式。从属于“简计划”。

License

Notifications You must be signed in to change notification settings

LongTengDao/j-regexp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

const { newRegExp } = require('@ltd/j-regexp');

const TAG_NAME = /[a-z][a-z\d]*/i;

const ATTRIBUTE_NAME = /[a-z][a-z\-]*/i;

const ATTRIBUTE_VALUE = newRegExp.i`
	(?:
		"[^"]*"
		|
		'[^']'
		|
		[a-z]+
	)
`;

const _ = /[\t\n\f\r\x20]/i;

const ATTRIBUTE = newRegExp.i`
	${_}+
	${ATTRIBUTE_NAME}
	(?:
		${_}*
		=
		${_}*
		${ATTRIBUTE_VALUE}
	)?
`;

const START_TAG = newRegExp.i`
	<${TAG_NAME}(?:${ATTRIBUTE})*${_}*>
`;

const END_TAG = newRegExp.i`
	</${TAG_NAME}${_}*>
`;

const SELF_CLOSING_TAG = newRegExp.i`
	<${TAG_NAME}(?:${ATTRIBUTE})*${_}+/>
`;
const { groupify } = require('@ltd/j-regexp');

console.log(groupify(['a', 'a', 'b', 'cc11', 'cc22']));
// '(?:[ab]|cc(?:11|22))'

console.log(groupify(['大𠮷', '大利']));
// '大(?:利|𠮷)' ('𠮷'.length===2)
console.log(groupify(['大𠮷', '大利'], true));// uFlag
// '大[𠮷利]'

About

More readable way for creating RegExp. Belong to "Plan J"./可读性更好的正则表达式创建方式。从属于“简计划”。

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published