Skip to content

Possible to remove in-text references? #678

Closed Answered by alimoges42
alimoges42 asked this question in Q&A
Discussion options

You must be logged in to vote

For anyone interested, I was able to use regex after all. I've tested it on a few examples for flexibility and it seems to work well. Code is below.

import re


def filter_numeric_citations(text: str) -> str:
    # Pattern for matching different citation formats
    citation_patterns = [
        # Single numbers or lists within parentheses/brackets
        r'\s*\((?:\d+(?:\s*,\s*\d+)*)\)(?=[\s\.,])',
        r'\s*\[(?:\d+(?:\s*,\s*\d+)*)\](?=[\s\.,])',

        # Ranges within parentheses/brackets
        r'\s*\((?:\d+\s*-\s*\d+)\)(?=[\s\.,])',
        r'\s*\[(?:\d+\s*-\s*\d+)\](?=[\s\.,])',

        # Mixed lists and ranges within parentheses/brackets
        r'\s*\((?:\d+(?:\s*-\s*\d+)?…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by alimoges42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant