Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save evandrocoan/0e997da5394a6cf973e3cc0ba2877920 to your computer and use it in GitHub Desktop.
Save evandrocoan/0e997da5394a6cf973e3cc0ba2877920 to your computer and use it in GitHub Desktop.
# Matching open parenthesis outside double or single quotes.md
# Copyright (c) 2019 Evandro Coan
# 
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
  1. Open and close parenthesis expressions outside single and double quotes:

    ".*?"(*SKIP)(?!)|(?<!\w)'.*?'(?!\w)(*SKIP)(?!)|(?:\()(?!\s|\))
    ".*?"(*SKIP)(?!)|(?<!\w)'.*?'(?!\w)(*SKIP)(?!)|(?<!\s|\()(?:\))
    1. https://regex101.com/r/OFeXIh/1/
    2. https://stackoverflow.com/questions/26003778/can-regex-match-all-the-words-outside-quotation-marks

    Now, not matching open and close parenthesis preceded by def and neither inside triple single or double quotes:

    (?s)".*?"(*SKIP)(?!)|(?<!\w)'.*?'(?!\w)(*SKIP)(?!)|(?s)""".*?"""(*SKIP)(?!)|(?<!\w)'''.*?'''(?!\w)(*SKIP)(?!)|def[^(]*\((*SKIP)(*F)|(?:\()(?!\s|\))
    (?s)".*?"(*SKIP)(?!)|(?<!\w)'.*?'(?!\w)(*SKIP)(?!)|(?s)""".*?"""(*SKIP)(?!)|(?<!\w)'''.*?'''(?!\w)(*SKIP)(?!)|def[^)]*\)(*SKIP)(*F)|(?<!\s|\()(?:\))

    Now, and no class word:

    (?s)".*?"(*SKIP)(?!)|(?<!\w)'.*?'(?!\w)(*SKIP)(?!)|(?s)""".*?"""(*SKIP)(?!)|(?<!\w)'''.*?'''(?!\w)(*SKIP)(?!)|(?:def|class)[^(]*\((*SKIP)(*F)|(?:\()(?!\s|\))
    (?s)".*?"(*SKIP)(?!)|(?<!\w)'.*?'(?!\w)(*SKIP)(?!)|(?s)""".*?"""(*SKIP)(?!)|(?<!\w)'''.*?'''(?!\w)(*SKIP)(?!)|(?:def|class)[^)]*\)(*SKIP)(*F)|(?<!\s|\()(?:\))
    1. https://regex101.com/r/ec0FgD/3
    2. https://stackoverflow.com/questions/50649369/how-to-properly-use-char-negation-to-do-word-non-fixed-width-backward-lookb
  2. Match everything all the lines which does not has the word c=50 and does not has anything on the form c=\d\d:

    c=50(*SKIP)(*F)|c=\d\d
    1. https://regex101.com/r/fCdsOE/1
    2. Imgur
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment