当前位置:网站首页>regular expression
regular expression
2022-07-08 01:30:00 【InfoQ】
RegExp - Regular expressions
Create a regular expression
// 1. Literal creation
const reg = /abcd/;
console.log(reg);
console.log(typeof reg);
// 2. Built in constructor creation
const reg2 = new RegExp('abcd');
console.log(reg2);
console.log(typeof reg2);
Two methods of regular expression
const reg = /abcd/;
// 1. test()
console.log(reg.test('aaabbbcccddd'));
console.log(reg.test('aaabcddddd'));
// 2. exec()
const res = reg.exec('aaabbbcccddd')
console.log(res);
const res2 = reg.exec('aaabcdddddabcdabcd');
console.log(res2);
Metacharacters of regular expressions - Basic metacharacter
1. \s
// Indicates that there needs to be one in the string Space character
const reg = /\s/ ;// Equivalent to / /
console.log(reg.test(' abcdefg'));
console.log(reg.test('abc d efg'));
// \S
// Indicates that there needs to be one in the string Non blank space character
const reg = /\S/
console.log(reg.test(' a'))
console.log(reg.test(' a a a '))
// 3. \t
// Indicates that there needs to be a... In your string tabs character
const reg = /\t/
console.log(reg.test(' ')) // Two spaces
console.log(reg.test(' ')) // A tab
// \d
// Indicates that there needs to be a... In your string Numbers character
const reg = /\d/
console.log(reg.test('abcdef'))
console.log(reg.test('ab1c1d111ef'))
// \D
// Indicates that there needs to be a... In your string The digital character
const reg = /\D/
console.log(reg.test('1234567890'))
console.log(reg.test('12a34a5a67a890'))
// \w
// Indicates that there needs to be a... In your string Numbers or letters or underscores character
const reg = /\w/
console.log(reg.test('[email protected]#$%$#@#$%$#$%$#$%$#'))
console.log(reg.test('[email protected]#123123$%$#@#$%$#$%asdasd$#$%$#'))
// \W
// Indicates that there needs to be a... In your string Alphanumeric underline Characters other than
const reg = /\W/
console.log(reg.test('asdasd123123123____'))
console.log(reg.test('asdasd123123123____%'))
console.log(reg.test('asdasd12312312##3____'))
// spot (.)
// Indicates that there needs to be a... In your string Non newline Content
const reg = /./
console.log(reg.test('\n'))
console.log(reg.test('a\nb'))
console.log(reg.test(' \n'))
// Oblique line (\)
// Indicates that there needs to be a letter in your string s
const reg = /s/
console.log(reg.test('abcd'))
console.log(reg.test('abcds'))
// Indicates that there needs to be a... In your string Space character
const reg2 = /\s/
console.log(reg2.test('abcdssss'))
console.log(reg2.test('abcdssss '))
// Indicates that there needs to be a... In your string Non newline Any character of
const reg3 = /./
console.log(reg3.test('asday'))
// Indicates that there needs to be a... In your string spot Text
const reg4 = /\./
console.log(reg4.test('asdasd'))
console.log(reg4.test('asdasd.'))
// Indicates that there needs to be a... In your string \ Text
const reg5 = /\\/
console.log(reg5.test('\\'))
边栏推荐
- Recommend a document management tool mendely Reference Manager
- 5. Discrete control and continuous control
- Leetcode notes No.7
- The persistence mode of redis - RDB and AOF persistence mechanisms
- Definition and classification of energy
- NPM Internal Split module
- EDP to LVDS conversion design circuit | EDP to LVDS adapter board circuit | capstone/cs5211 chip circuit schematic reference
- [loss function] entropy / relative entropy / cross entropy
- On the concept and application of filtering in radar signal processing
- break algorithm---刷题map
猜你喜欢
Common configurations in rectangular coordinate system
Design method and reference circuit of type C to hdmi+ PD + BB + usb3.1 hub (rj45/cf/tf/ sd/ multi port usb3.1 type-A) multifunctional expansion dock
Gnuradio operation error: error thread [thread per block [12]: < block OFDM_ cyclic_ prefixer(8)>]: Buffer too small
2022 R1 fast opening pressure vessel operation test question bank and R1 fast opening pressure vessel operation free test questions
Redis集群
Definition and classification of energy
5. Contrôle discret et contrôle continu
2、TD+Learning
General configuration toolbox
Gnuradio 3.9 using OOT custom module problem record
随机推荐
common commands
4、策略学习
Scheme selection and scheme design of multifunctional docking station for type C to VGA HDMI audio and video launched by ange in Taiwan | scheme selection and scheme explanation of usb-c to VGA HDMI c
Chapter improvement of clock -- multi-purpose signal modulation generation system based on ambient optical signal detection and custom signal rules
Led serial communication
Chapter XI feature selection
Guojingxin center "APEC investment +": some things about the Internet sector today | observation on stabilizing strategic industrial funds
The persistence mode of redis - RDB and AOF persistence mechanisms
HDMI to VGA acquisition HD adapter scheme | HDMI to VGA 1080p audio and video converter scheme | cs5210 scheme design explanation
Transportation, new infrastructure and smart highway
Cs5212an design display to VGA HD adapter products | display to VGA Hd 1080p adapter products
2022 operation certificate examination for main principals of hazardous chemical business units and main principals of hazardous chemical business units
2022 high voltage electrician examination skills and high voltage electrician reexamination examination
Application of state mode in JSF source code
Common effects of line chart
Basic realization of line chart (II)
The Ministry of housing and urban rural development officially issued the technical standard for urban information model (CIM) basic platform, which will be implemented from June 1
Euler Lagrange equation
Gnuradio operation error: error thread [thread per block [12]: < block OFDM_ cyclic_ prefixer(8)>]: Buffer too small
Capstone/cs5210 chip | cs5210 design scheme | cs5210 design data