Python Forum
Use or raw string on regular expressions
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Use or raw string on regular expressions
#4
(May-09-2024, 12:16 PM)deanhystad Wrote: \. Is not an escape sequence. \n is an escape sequence. A backslash by itself does not mean there is an escape sequence. The next character has to be n, b, t, x or backslash for it to be an escape sequence. I may have missed an escape character in that list which is why I use raw strings any time I write regex patterns.

Thanks for the quick answer guys.

\. is not an escape sequence? If I want to search for a literal "." I have to escape it with "\.", am I wrong? The same that for "\n", if I want to search for a literal "\n" I have to escape it with ''\\n" or r'\n".
Sorry if you find this as a very basic question, I just find it very confusing.
Reply


Messages In This Thread
RE: Use or raw string on regular expressions - by Zaya_pool - May-09-2024, 01:12 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Information Do regular expressions still need raw strings? bobmon 3 496 May-03-2024, 09:05 AM
Last Post: rishika24
  Recursive regular expressions in Python risu252 2 1,693 Jul-25-2023, 12:59 PM
Last Post: risu252
Sad Regular Expressions - so close yet so far bigpapa 5 1,197 May-03-2023, 08:18 AM
Last Post: bowlofred
  Having trouble with regular expressions mikla 3 2,785 Mar-16-2021, 03:44 PM
Last Post: bowlofred
  Regular expression: cannot find 1st number in a string Pavel_47 2 2,523 Jan-15-2021, 04:39 PM
Last Post: bowlofred
  Regular expression: return string, not list Pavel_47 3 2,640 Jan-14-2021, 11:49 AM
Last Post: Pavel_47
  Regular Expressions pprod 4 3,281 Nov-13-2020, 07:45 AM
Last Post: pprod
  simple f-string expressions to access a dictionary Skaperen 0 1,608 Jul-15-2020, 05:04 AM
Last Post: Skaperen
  Format phonenumbers - regular expressions Viking 2 2,052 May-11-2020, 07:27 PM
Last Post: Viking
  regular expressions in openpyxl. format picnic 0 2,587 Mar-28-2020, 09:47 PM
Last Post: picnic

Forum Jump:

User Panel Messages

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