Sandeep Krishnan
Sandeep Krishnan

Reputation: 465

Python match a number within a string

I need to check if a string matches ORA-16252: unable to extend segment by <any value> in tablespace. Here <any value> can be any number. How do I match the string in python? Is there a regular expression for that?

Upvotes: 0

Views: 716

Answers (2)

Johan R&#229;de
Johan R&#229;de

Reputation: 21418

regex = re.compile(r'ORA-16252: unable to extend segment by \d+ in tablespace')
if regex.match(s):
    ...

Upvotes: 3

Rohit Jain
Rohit Jain

Reputation: 213391

\\d+ is used to match one or more number of digits is continuity. So, you can just add it in place of your <any value> to match any number.

Rest of the strings, since it does not vary as you are saying, keep it as it is.

m = re.search(r'ORA-16252: unable to extend segment by \d+ in tablespace', 
               yourString)

if m is not None:
    # set your value

Upvotes: 0

Related Questions