Linked Questions
57 questions linked to/from What exactly is a "raw string regex" and how can you use it?
47 votes
6 answers
189k views
Python match a string with regex [duplicate]
I need a python regular expression to check if a word is present in a string. The string is separated by commas, potentially. So for example, line = 'This,is,a,sample,string' I want to search based ...
0 votes
1 answer
2k views
Regex Python - Backslash [duplicate]
I am trying to remove tags in text that are identified by a backslash. For example, for the phrase 'Hello \tag world', I'd like to return the phrase 'Hello world'. I've tried the following but it ...
-1 votes
1 answer
565 views
What is actual meaning of r'^ icon in every urls? can any one explain what is his meaning and how important this are in details [duplicate]
This is the code in question: url(r'^dreamreals/', ListView.as_view(model = Dreamreal, template_name = "dreamreal_list.html")), )
-1 votes
1 answer
197 views
Isn't the 'r' letter making the regex pattern string literal? [duplicate]
I had thought the 'r' prefix in the pattern is to make sure that anything in the pattern will be interpreted as string literal, so that I don't have to use escape, but in this case below, I still have ...
0 votes
1 answer
100 views
Not getting decimals when extracting values [duplicate]
So I am practicing data wrangling and I have encountered an issue. food['GPA'].unique() And the output is array(['2.4', '3.654', '3.3', '3.2', '3.5', '2.25', '3.8', '3.904', '3.4', '3.6', '3.1'...
0 votes
0 answers
97 views
I'm getting error "error: bad escape \d at position 1" when I'm trying to convert date format using regex and replace [duplicate]
I'm getting error "error: bad escape \d at position 1" when working on date formatting. I have to convert from format 11/13.2015 to 11/13/2015. I'm replacing using a regex and converting to ...
0 votes
0 answers
70 views
Regex works in regex101, but not in python code [duplicate]
I have this text: a href="#" class="s-navigation--item js-gps-track js-products-menu" aria-controls="products-popover" data-controller="s-popover" data-action=&...
0 votes
0 answers
51 views
Why python interprets \\ as a "Bad escape" [duplicate]
Using the re library my problem is in this line x = re.match("([A-Z]:|home∼|\.\.?)\\", txt) Im trying to get a match with a disk "E:", "home∼", or a parent folder ".....
0 votes
0 answers
44 views
Regular Expression tested but not working [duplicate]
I have a fairly simple regular expression pattern that I'm trying to match with some raw string literals. I've tested the pattern here (https://regex101.com/r/xT6xU8/2) and it works perfectly, but in ...
0 votes
0 answers
38 views
What are these re.search meta characters doing? Where is my address? Not fully understanding syntax and RB [duplicate]
my_address = re.search(rb'\x80\xC9.{4}\x94\x12\x8A\x41\x08', bytes).start() + 5 Read the doc but I'm a bit confused. My guess is \x80\xC9\BYTE\BYTE\BYTE\BYTE\BYTE\x94\x12\x8A\x41\x08\BYTE\BYTE\BYTE\...
0 votes
0 answers
32 views
Regex matching with \b [duplicate]
I dont understand why my string is not matching : re.findall('\bbp\b', 'station bp coucou') According to regex101 it should match ...
417 votes
19 answers
1.1m views
Remove all special characters, punctuation and spaces from string
I need to remove all special characters, punctuation and spaces from a string so that I only have letters and numbers.
924 votes
8 answers
809k views
What exactly do "u" and "r" string prefixes do, and what are raw string literals?
While asking this question, I realized I didn't know much about raw strings. For somebody claiming to be a Django trainer, this sucks. I know what an encoding is, and I know what u'' alone does since ...
375 votes
5 answers
277k views
Escaping regex string
I want to use input from a user as a regex pattern for a search over some text. It works, but how I can handle cases where user puts characters that have meaning in regex? For example, the user wants ...
15 votes
3 answers
9k views
Python Regex escape operator \ in substitutions & raw strings
I don't understand the logic in the functioning of the scape operator \ in python regex together with r' of raw strings. Some help is appreciated. code: import re text=' esto .es 10 . er - 12 .23 ...