Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Regular Expressions
#5
Without regex (kiss):
poem.replace('ai', '*/*').replace('hi', '*/*')
A regex, which will detect ai and hi:
r'ai|hi'
You can use re.sub for replacement.
To construct or check a regex, you should visit this site:
https://regex101.com/
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Messages In This Thread
Regular Expressions - by amitalable - Mar-13-2019, 01:06 PM
RE: Regular Expressions - by ichabod801 - Mar-13-2019, 03:05 PM
RE: Regular Expressions - by amitalable - Mar-14-2019, 11:31 AM
RE: Regular Expressions - by ichabod801 - Mar-14-2019, 01:11 PM
RE: Regular Expressions - by DeaD_EyE - Mar-14-2019, 04:31 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Search in a file using regular expressions ADELE80 2 879 Dec-18-2024, 12:29 PM
Last Post: ADELE80
  Use or raw string on regular expressions Zaya_pool 5 1,837 May-09-2024, 06:10 PM
Last Post: Zaya_pool
Information Do regular expressions still need raw strings? bobmon 3 2,923 May-03-2024, 09:05 AM
Last Post: rishika24
  Recursive regular expressions in Python risu252 2 5,557 Jul-25-2023, 12:59 PM
Last Post: risu252
Sad Regular Expressions - so close yet so far bigpapa 5 2,355 May-03-2023, 08:18 AM
Last Post: bowlofred
  Having trouble with regular expressions mikla 3 3,631 Mar-16-2021, 03:44 PM
Last Post: bowlofred
  Regular Expressions pprod 4 4,666 Nov-13-2020, 07:45 AM
Last Post: pprod
  Format phonenumbers - regular expressions Viking 2 2,707 May-11-2020, 07:27 PM
Last Post: Viking
  regular expressions in openpyxl. format picnic 0 3,145 Mar-28-2020, 09:47 PM
Last Post: picnic
  Unexpected (?) result with regular expressions guraknugen 2 2,994 Jan-18-2020, 02:33 PM
Last Post: guraknugen

Forum Jump:

User Panel Messages

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