regex - How to match a substring surrounded by known prefix and suffix in javascript -


given string, such as:

example string intended nested string match.

how isolate substring knowing prefix , suffix it, e.g. between intended , to match?

use regular expressions non-capturing parentheses, so:

string = 'example string intended nested string match.'; regexp = /(?:intended)(.*)(?:to match)/; firstmatch = regexp.exec(string)[1]; // " nested string " 

the question mark has several uses in regular expressions, parentheses question mark colon form (?:more regex) non-capturing parentheses.

see mdn more details of exec(), string.match(), , regular expressions.


Comments

Popular posts from this blog

java - Cast from Object to List<String>: CastClassException -

How to set a border for android Imageview in Longpress? -

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -