Skip to content

How can I make a multiple search and replace on files? #12

@ioanf2

Description

@ioanf2

hello. How can I make a multiple search and replace on files on a Python code? For example I have a folder with 300 html files. I want to use 5 regex find/replace formulas, in the order I want, as to modify the content of those files.

Besides, I must use also the option Dot matches newsline for some regex formulas.

FIND: (<link rel="canonical" href="(.*?)" />.*?)(<meta property="og:url" content=").*?("\/>)
Replace by: \1\3\2\4

and this is a simple find/replace regex:

FIND: <title>.*\K\|(.*)(</title>)
Replace by: \x20|\x20Something Else \(zh\)\x20\2

So both formulas, must be use in the same Python script, one after another, so after run the code to modify all my files from folder. How can I do that?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions