Home  >  Article  >  Web Front-end  >  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

高洛峰
高洛峰Original
2017-01-09 15:51:562057browse

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

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

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

3. js intercepts the content after a certain string:

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

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!


Statement:
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