Home > Article > Web Front-end > JS regular method to intercept the content between two strings and the content before and after the string
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);//结果aaabbbcccddd3. js intercepts the content after a certain string:
var str = "aaabbbcccdddeeefff"; str = str.match(/aaa(\S*)/)[1]; alert(str);//结果bbbcccdddeeefffI 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!