Note that there are some explanatory texts on larger screens.

plurals
  1. POBasic Regex Practice
    text
    copied!<p>A simple question I was unable to find any similar examples which did not recommend using outside libraries, I have an exercise in which we have mock data similar to HTML/XML and we are restricted to using only Java regex library to parse and manipulate it. We want to translate the data into a map. The format is:</p> <pre class="lang-none prettyprint-override"><code>&lt;key&gt; data words here &lt;/key&gt;... </code></pre> <p>...where each data word will be added to the map with the key separately, so the resulting map should look like this:</p> <pre class="lang-none prettyprint-override"><code>{key, data key, words key, here} </code></pre> <p>I have come up with some solutions which first find and store the key using a regex, then match the inside of the key tag, store that data in a string, tokenize it using a space and bracket delimiters, and loop through the resulting list to write to the map. Is there a more straightforward or elegant method of doing this where I could capture the key and an array/list of the data words using just regex and eliminating the use of the tokenizer?</p> <p>Some sample data below (notice there are no nested tags which makes this much simpler than parsing HTML):</p> <pre class="lang-none prettyprint-override"><code>&lt;author&gt; A. Cau, R. Kuiper, and W.-P. de Roever. &lt;/author&gt; &lt;title&gt; Formalising Dijkstra's development strategy within Stark's formalism. &lt;/title&gt; &lt;editor&gt; In C. B. Jones, R. C. Shaw, and T. Denvir, editors, &lt;/editor&gt; &lt;booktitle&gt; Proc. 5th. BCS-FACS Refinement Workshop, &lt;/booktitle&gt; &lt;date&gt; 1992. &lt;/date&gt; </code></pre> <p>(all on one line - line breaks added for readability)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload