Python Forum
Hide symbol or characters in regular expression
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Hide symbol or characters in regular expression
#1
I'm trying to find a full list of domain names from a imported text file and the correct regular expression used is this

import re
hand = open('mbox-short.txt')
for line in hand:
    line = line.rstrip()
    x = re.findall('[a-zA-Z0-9]\S*@(\S*[a-zA-Z0-9])', line)
    if len(x) > 0:
        print(x)
However the regular expression created is way too long, so i came up with this:

x = re.findall('@\S+', line)
By doing the above, i'm able to get the same exact as the longer regular expressions, however because I specify the @ in front, the results printed @ on every line too. So i'm trying to figure out if there is a way or code that I can use to hide the @ symbol in the result? Reason being it will save me the trouble of writing the longer regular expression as it's a pain in the neck.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  data validation with specific regular expression shaheen07 0 296 Jan-12-2024, 07:56 AM
Last Post: shaheen07
  Decryption not working if key has same symbol like text Paragoon2 0 292 Nov-11-2023, 09:32 PM
Last Post: Paragoon2
  Convert Excel file into csv with Pipe symbol.. mg24 4 1,289 Oct-18-2022, 02:59 PM
Last Post: Larz60+
  Regular Expression search to comment lines of code Gman2233 5 1,594 Sep-08-2022, 06:57 AM
Last Post: ndc85430
  List Creation and Position of Continue Statement In Regular Expression Code new_coder_231013 3 1,602 Jun-15-2022, 12:00 PM
Last Post: new_coder_231013
  Need help with my code (regular expression) shailc 5 1,872 Apr-04-2022, 07:34 PM
Last Post: shailc
  Regular Expression for matching words xinyulon 1 2,132 Mar-09-2022, 10:34 PM
Last Post: snippsat
  regular expression question Skaperen 4 2,419 Aug-23-2021, 06:01 PM
Last Post: Skaperen
  How can I find all combinations with a regular expression? AlekseyPython 0 1,637 Jun-23-2021, 04:48 PM
Last Post: AlekseyPython
  Python Regular expression, small sample works but not on file Acernz 5 2,860 Jun-09-2021, 08:27 PM
Last Post: bowlofred

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020