0

I am trying to fetch some database details from wp-config.php file. Unfortunately I stick on the part where I have the line that contains the DB_NAME and I could not extract the database_name only from the following:

define('DB_NAME', 'database_name');

Help is much appreciated!

1 Answer 1

2

Iterate over each line and then apply re.search like below.

>>> x = "define('DB_NAME', 'database_name');"
>>> re.search(r"define\('DB_NAME',\s*'([^']*)'\);", x).group(1)
'database_name'

or

for line in f:
    if 'DB_NAME' in line:
        print line.split("'")[3]
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.