سؤال

I want to use PHP to search a directory of files (views.xml files) and pull out values from any attributes named "window_title_key".

The attributes look like this:

<put-attribute name="content" value="/WEB-INF/views/login/content.vm" type="velocity" />
<put-attribute name="window_title_key" value="window_title_login_page" type="string"/>

For each file, I want to ignore all lines except those that start with <put-attribute name="window_title_key".

Then, on those lines, I want to extract the value of that attribute. In this example, the value would be window_title_login_page.

I want the result to be an array of all of the values of all window_title_key attributes.

What is the regex pattern I should use?

It should be flexible enough to allow for variable whitespace (before the word "value" and the double-quotes of the "name" property).

هل كانت مفيدة؟

المحلول

Per your regex requirements:

/^\Q<put-attribute name="window_title_key" value="\E([^"]*)"/m

This should suffice. Take the matches from group 1. Variable whitespace is possible inside and after the value attribute.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top