Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Since you request only first value in a string to be replaced (by using <strong>boost::format_first_only</strong> flag) original string</p> <pre><code>"Mr $SURNAME$ from $LOCATION$" </code></pre> <p>will be converted into </p> <pre><code>"Mr ACTUAL_VAL from $LOCATION$" </code></pre> <p>on first iteration and then </p> <pre><code>" from ACTUAL_VAL" </code></pre> <p>will be appended to it since you explicitly set begin to "what[0].second. so final output is</p> <pre><code>"Mr ACTUAL_VAL from $LOCATION$ from ACTUAL_VAL" </code></pre> <p>which is not what you need. Here is working example that has side effect - it modifies fileLine:</p> <pre><code> const boost::regex expression( "\\$[\\w]+\\$" ); string fileLine( "Mr $SURNAME$ from $LOCATION$" ); string outLine; string::const_iterator begin = fileLine.begin(); string::const_iterator end = fileLine.end(); boost::match_results&lt;string::const_iterator&gt; what; boost::match_flag_type flags = boost::match_default; while ( regex_search( begin, end, what, expression, flags ) ) { const char* actualValue = valuesMap[what[0]]; ostringstream t( ios::out | ios::binary ); ostream_iterator&lt;char, char&gt; oi( t ); boost::regex_replace( oi, begin, end, expression, `enter code here`actualValue, boost::match_default | boost::format_first_only ); fileLine.assign(t.str()); begin = fileLine.begin(); end = fileLine.end(); } std::cout &lt;&lt; fileLine &lt;&lt; std::endl; </code></pre> <p>If you don't want to modify fileLine, then you should make "begin" and "end" to mark the beginning and end of sliding window that contains exactly one pattern.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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