As dicussed in comments, you should try to fix the data source. However, here is the regex to print the expected result:
---
- name: Sample playbook
connection: local
#gather_facts: false
hosts: localhost
vars:
String: "Test_[u'Net::Route Domain: RD2001']"
tasks:
- debug:
msg: "{{ String| regex_replace('^(\\w+)\\[.*:\\s+([\\w]+).*', '\\1\\2') }}"
Results:
PLAY [Sample playbook] ***************************************************************************************************************
TASK [Gathering Facts] ***************************************************************************************************************
ok: [localhost]
TASK [debug] *************************************************************************************************************************
ok: [localhost] => {
"msg": "Test_RD2001"
}
PLAY RECAP ***************************************************************************************************************************
localhost : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
u'Net::Route Domain: RD2001'is suspicious looking. How does this string get built in the first place, because it looks like python printing an internal representation of a unicode string rather than normal string variable contents, or[]looks like you are printing an array containing the stringNet::Route...as a string itself^matches the start of the string so nothing comes before, and \w+ matches one or more "word characters", non-whitespace, non-punctuation, so together they match and capture the wordTest_at the start of the string, before the first[u'