0

I'm not familiar with regular expressions and am not sure what I'm doing wrong.

reg=re.compile('[a-zA-z]+?') #regular expression checks for at least one alphabetic character

print(bool(reg.match('*ab*')))

I would like this to result in True. It doesn't matter where the alphabetic character occurs in the string.

jfang
  • 57
  • 3

2 Answers2

0

You can also change your pattern if you want to keep compile and match:

re.compile('.*[A-Za-z].*')
Anatoliy R
  • 1,749
  • 2
  • 14
  • 20
-1

You can check your matches by using the re.match function.

Here is a doc on it: https://www.guru99.com/python-regular-expressions-complete-tutorial.html

import re

string = "someWord"

Output = re.match('[a-zA-z]+?', string)

if Output:
    print('match found')
High-Octane
  • 1,104
  • 5
  • 19