Regex matches attribute value

What will be the regular expression to return 'details.jsp' (without quotes!) From this source tag. I can easily match all value = "details.jsp", but I have problems with matching content inside the attribute.

<s:include value="details.jsp" />

Any help is much appreciated!

thanks

Lawrence

+4
source share
1 answer

/value=["']([^'"]+)/ puts "details.jsp" in the first capture group.

Edit:

In response to ircmaxell's comment, if you really need it, the following expression is more flexible:

/value=(['"])(.+)\1/

It will correspond to things like <s:include value="something['else']"> , but just note that the value will be placed in the second capture group.

But, as mentioned earlier, a regular expression is not what you want to use for XML parsing (unless this is a very simple case), so don't invest too much time in complex regular expressions when you should use a parser.

+5
source

Source: https://habr.com/ru/post/1312883/


All Articles