Looking for a Python/Bash coder

Status
Not open for further replies.

GermanCPA

Junior Member
Joined
Mar 31, 2025
Messages
167
Reaction score
110
Hi,

I am looking for a python coder for an ultra small script.

I tried using ChatGPT but it is not working.

The script should remove 2-3 line breaks that are incorrectly in a regex.

Currently:

Code:
/(user|mailbox|recipient|rcpt|local part|address|account|mail drop|ad(d?)ressee) (has|has been|is)? *(currently|temporarily
+)?(disabled|expired|inactive|not

activated)/ inactive-mailbox
/(conta|usu.rio) inativ(a|o)/ inactive-mailbox
/Too many (bad|invalid|unknown|illegal|unavailable) (user|mailbox|recipient|rcpt|local part|address|account|mail drop|ad(d?)ressee)/ other
/(No such|bad|invalid|unknown|illegal|unavailable) (local +)?(user|mailbox|recipient|rcpt|local part|address|account|mail drop|ad(d?)ressee)/ bad-mailbox
/(user|mailbox|recipient|rcpt|local part|address|account|mail drop|ad(d?)ressee) +(\S+@\S+ +)?(not (a +)?valid|not known|not here|not found|does not
exist|bad|

invalid|unknown|illegal|unavailable)/ bad-mailbox

Result should be:
Code:
/(user|mailbox|recipient|rcpt|local part|address|account|mail drop|ad(d?)ressee) (has|has been|is)? *(currently|temporarily +)?(disabled|expired|inactive|not activated)/ inactive-mailbox
/(conta|usu.rio) inativ(a|o)/ inactive-mailbox
/Too many (bad|invalid|unknown|illegal|unavailable) (user|mailbox|recipient|rcpt|local part|address|account|mail drop|ad(d?)ressee)/ other
/(No such|bad|invalid|unknown|illegal|unavailable) (local +)?(user|mailbox|recipient|rcpt|local part|address|account|mail drop|ad(d?)ressee)/ bad-mailbox
/(user|mailbox|recipient|rcpt|local part|address|account|mail drop|ad(d?)ressee) +(\S+@\S+ +)?(not (a +)?valid|not known|not here|not found|does not exist|bad|invalid|unknown|illegal|unavailable)/ bad-mailbox

Give me the solution and a $ amount to be paid by crypto.
 
You dont need to use regex, just use notepad++
chose Edit > Line operations > Remove Empty Lines and NotePad++ removes ALL the empty lines
 
Try this.

Code:
import re

def fix_regex_line_breaks(input_text):
    # Split into lines and strip trailing whitespace
    lines = [line.rstrip() for line in input_text.splitlines()]
    patterns = []
    current = []
    
    for line in lines:
        if not line:  # Skip empty lines
            continue
            
        if line.startswith('/'):  # Start of new pattern
            if current:  # Save previous pattern if exists
                patterns.append(''.join(current))
                current = []
            current.append(line)
        elif any(line.endswith(flag) for flag in [' inactive-mailbox', ' other', ' bad-mailbox']):
            # Add space before flag if needed
            if not line.startswith(' '):
                line = ' ' + line
            current.append(line)
            patterns.append(''.join(current))
            current = []
        else:
            # Handle special cases
            if current:
                last = current[-1]
                # Handle "not activated" case
                if last.endswith('not') and 'activated' in line:
                    current[-1] = last + ' ' + line
                # Handle "does not exist" case
                elif last.endswith('does not') and 'exist' in line:
                    current[-1] = last + ' ' + line
                # Handle "temporarily +" case
                elif 'temporarily' in last and '+' in line:
                    current[-1] = last + ' ' + line
                # Handle "|invalid" case - no space after |
                elif '|' in line:
                    # Remove any spaces after | but keep other spaces
                    line = re.sub(r'\|\s+', '|', line)
                    current.append(line)
                else:
                    current.append(line)
            else:
                current.append(line)
    
    # Add any remaining pattern
    if current:
        patterns.append(''.join(current))
    
    # Post-process to ensure correct spacing
    result = []
    for pattern in patterns:
        # Fix temporarily + spacing
        pattern = re.sub(r'temporarily\s*\+', 'temporarily +', pattern)
        # Fix spaces after |
        pattern = re.sub(r'\|\s+', '|', pattern)
        result.append(pattern)
    
    return '\n'.join(result)

# Example usage
if __name__ == '__main__':
    with open('input.txt', 'r') as f:
        input_text = f.read()
    
    fixed_text = fix_regex_line_breaks(input_text)
    
    with open('output.txt', 'w') as f:
        f.write(fixed_text)
        print("Successfully wrote fixed patterns to output.txt")
 
Status
Not open for further replies.
Back
Top