0

I am actually working on Python regex that excludes certain file path. I am creating this regex in a property file , and then passing to my python code

import re
regex = ".*-old-.*"
sequence = "/tmp/file-old-1"

print re.match(regex, sequence) 

Now , I want to build a regex that do not match for anything. Is it possible to have so. Any help will be helpful !

Thanks !

2
  • 1
    What do you mean? typically regex is used to match strings containing a pattern you define. When you say do not match anything, do you mean perform an action if your current regex has no match? Whats your input and expected output? Commented Apr 7, 2021 at 1:39
  • You tagged this for python-3.x, and it has a syntax error for Python 3, and guaranteed broken code in any version of Python (// is not a comment character in Python, so you're trying to divide the result of re.match by True). If you're going to provide code samples, at least make them legal code. Commented Apr 7, 2021 at 1:44

1 Answer 1

1

There are the special characters ^ and $ to denote the beggining and ending of the text being matched. Any pattern that have text before the beggining or after the end will have no match:

In [113]: re.findall(r".^", "any text")
Out[113]: []
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.