Home > Web Front-end > JS Tutorial > JS regular method to intercept the content between two strings and the content before and after the string

JS regular method to intercept the content between two strings and the content before and after the string

高洛峰
Release: 2017-01-09 15:51:56
Original
2094 people have browsed it

The example of this article describes the method of JS regular interception of the content between two strings and the content before and after the string. Share it with everyone for your reference, the details are as follows:

1. js intercepts the content between two strings:

var str = "aaabbbcccdddeeefff";
str = str.match(/aaa(\S*)fff/)[1];
alert(str);//结果bbbcccdddeee
Copy after login

##2. js intercepts the content in front of a certain string:

var str = "aaabbbcccdddeeefff";
tr = str.match(/(\S*)fff/)[1];
alert(str);//结果aaabbbcccddd
Copy after login

3. js intercepts the content after a certain string:

var str = "aaabbbcccdddeeefff";
str = str.match(/aaa(\S*)/)[1];
alert(str);//结果bbbcccdddeeefff
Copy after login

I hope this article will be helpful to everyone in JavaScript programming.

For more related articles on JS regular methods of intercepting the content between two strings and the content before and after the string, please pay attention to the PHP Chinese website!


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template