gpt-4.1-mini-2025-04-14· OpenAI
LMArena Human Preference 140K
In a multiline text string replace all substrings that begin with '@' with cobsecutively…
- User
In a multiline text string replace all substrings that begin with '@' with cobsecutively numbered strings of the form
@user-${currentNumber} - Assistant
Certainly! Here's a Python example that replaces all substrings starting with
@in a multiline text with consecutively numbered strings like@user-1,@user-2, etc.pythonimport re def replace_at_tags(text): counter = 0 def replacer(match): nonlocal counter counter += 1 return f"@user-{counter}" # This regex matches substrings starting with '@' followed by word characters pattern = r'@\w+' return re.sub(pattern, replacer, text) # Example usage: text = """Hello @alice, Please meet @bob and @charlie. Thanks, @dave.""" result = replace_at_tags(text) print(result)
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.