Word boundary detection doesn't seem to work for me in Python re
up vote
0
down vote
favorite
I tried using:
>>> wbpat='btestb'
>>> re.findall(wbpat, 'a test tested in testing')
The result that expected to get was ['test'] but somehow I am getting an empty list. What could be the problem...
python regex
add a comment |
up vote
0
down vote
favorite
I tried using:
>>> wbpat='btestb'
>>> re.findall(wbpat, 'a test tested in testing')
The result that expected to get was ['test'] but somehow I am getting an empty list. What could be the problem...
python regex
see also: stackoverflow.com/questions/30164054/…
– Sundeep
Nov 20 at 6:46
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I tried using:
>>> wbpat='btestb'
>>> re.findall(wbpat, 'a test tested in testing')
The result that expected to get was ['test'] but somehow I am getting an empty list. What could be the problem...
python regex
I tried using:
>>> wbpat='btestb'
>>> re.findall(wbpat, 'a test tested in testing')
The result that expected to get was ['test'] but somehow I am getting an empty list. What could be the problem...
python regex
python regex
asked Nov 20 at 6:41
just inquisitive
1669
1669
see also: stackoverflow.com/questions/30164054/…
– Sundeep
Nov 20 at 6:46
add a comment |
see also: stackoverflow.com/questions/30164054/…
– Sundeep
Nov 20 at 6:46
see also: stackoverflow.com/questions/30164054/…
– Sundeep
Nov 20 at 6:46
see also: stackoverflow.com/questions/30164054/…
– Sundeep
Nov 20 at 6:46
add a comment |
1 Answer
1
active
oldest
votes
up vote
4
down vote
b
is an escape code for a backspace (length 1 string). Use r'btestb'
. The leading r
indicates to the Python interpreter that it should interpret each character in the string as a literal single character (a "raw" string) and ignore escape sequences.
Example:
>>> len('btestb') # <backspace>test<backspace>
6
>>> len(r'btestb') # <backslash>btest<backslash>b
8
>>> import re
>>> re.findall(r'btestb','a test tested in testing')
['test']
It's a good habit to use a raw string for regular expressions in Python.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
b
is an escape code for a backspace (length 1 string). Use r'btestb'
. The leading r
indicates to the Python interpreter that it should interpret each character in the string as a literal single character (a "raw" string) and ignore escape sequences.
Example:
>>> len('btestb') # <backspace>test<backspace>
6
>>> len(r'btestb') # <backslash>btest<backslash>b
8
>>> import re
>>> re.findall(r'btestb','a test tested in testing')
['test']
It's a good habit to use a raw string for regular expressions in Python.
add a comment |
up vote
4
down vote
b
is an escape code for a backspace (length 1 string). Use r'btestb'
. The leading r
indicates to the Python interpreter that it should interpret each character in the string as a literal single character (a "raw" string) and ignore escape sequences.
Example:
>>> len('btestb') # <backspace>test<backspace>
6
>>> len(r'btestb') # <backslash>btest<backslash>b
8
>>> import re
>>> re.findall(r'btestb','a test tested in testing')
['test']
It's a good habit to use a raw string for regular expressions in Python.
add a comment |
up vote
4
down vote
up vote
4
down vote
b
is an escape code for a backspace (length 1 string). Use r'btestb'
. The leading r
indicates to the Python interpreter that it should interpret each character in the string as a literal single character (a "raw" string) and ignore escape sequences.
Example:
>>> len('btestb') # <backspace>test<backspace>
6
>>> len(r'btestb') # <backslash>btest<backslash>b
8
>>> import re
>>> re.findall(r'btestb','a test tested in testing')
['test']
It's a good habit to use a raw string for regular expressions in Python.
b
is an escape code for a backspace (length 1 string). Use r'btestb'
. The leading r
indicates to the Python interpreter that it should interpret each character in the string as a literal single character (a "raw" string) and ignore escape sequences.
Example:
>>> len('btestb') # <backspace>test<backspace>
6
>>> len(r'btestb') # <backslash>btest<backslash>b
8
>>> import re
>>> re.findall(r'btestb','a test tested in testing')
['test']
It's a good habit to use a raw string for regular expressions in Python.
edited Nov 20 at 6:52
answered Nov 20 at 6:43
Mark Tolonen
89.7k12107175
89.7k12107175
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53387563%2fword-boundary-detection-doesnt-seem-to-work-for-me-in-python-re%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
see also: stackoverflow.com/questions/30164054/…
– Sundeep
Nov 20 at 6:46