in reply to Re^5: regex subst not DWIM
in thread regex subst not DWIM

Works for the small dataset, and I have moved to a live example, in which some of the methods already have headers and we want to leave them alone.

Input snippet:

/// <summary> /// Checks to see if the data on the clipboard supports /// the given data type. /// </summary> /// <param name="dataType">The data type to check for.</param> /// <returns><c>true</c> if the data type is present.</returns +> public bool ClipboardDataHasType(string dataType) { return dataType == m_dataType; } /// <summary> /// Gets the clipboard data. /// </summary> /// <param name="dataType">Type of the data.</param> /// <returns> /// The data on the clipboard matching the datatype /// </returns> public object GetClipboardData(string dataType)
gets turned into output snippet:
/// <summary> /// Checks to see if the data on the clipboard supports /// the given data type. /// </summary> /// <param name="dataType">The data type to check for.</param> /// <returns><c>true</c> if the data type is present.</returns +> /// <summary> /// public bool ClipboardDataHasType(string dataType) /// </summary> /// <param name="dataType">string</param> public bool ClipboardDataHasType(string dataType) { return dataType == m_dataType; } /// <summary> /// Gets the clipboard data. /// </summary> /// <param name="dataType">Type of the data.</param> /// <returns> /// The data on the clipboard matching the datatype /// </returns> /// <summary> /// public object GetClipboardData(string dataType) /// </summary> /// <param name="dataType">string</param> public object GetClipboardData(string dataType)
Basically, the if ($file =~ /$comment$method/) { line is never matching, where $method is the declaration line and $comment is:
\\s*///\\s*<summary>\\s*///.*\\n\\s*///\\s*</summary>\\n(\\s*///.*\\n) +*
This is the case whether I specify s, m, or both (in either sequence) for the matching.

Replies are listed 'Best First'.
Re^7: regex subst not DWIM
by suaveant (Parson) on Dec 21, 2007 at 14:23 UTC
    Rather than doing the complex regex at the end, I would check for it in the read loop, myself...

    Maybe have a has_header flag that you increment if you see a //\s*

    line and unset it once you match the method, and skip to the next line.

                    - Ant
                    - Some of my best work - (1 2 3)