2

I have hundreds of text files with contents of this type (these are .txt content files from Kirby CMS):

Attributes:

- attribute: ''

----

Materials:

- 
  material: ""
  price: 0
  available: 'true'
  default: 'true'
  material_variations:
    - 
      variations:
        - 
          option: 
          variation: —
          price: "0"
          variation_available: 'true'
        - 
          option: 
          variation: ""
          price: "0"
          variation_available: 'true'

----

Price: 0

I want to remove the part from Materials: to the next ----, so the above snippet becomes:

Attributes:

- attribute: ''

----

Price: 0

I am searching for a regular expression to achieve that, but some things that I thought could maybe work (e.g. \bMaterials\b[^]\b----\b), produce an error in VSCode.

1 Answer 1

1

The [^] construct only works in the Find and Replace in-document search tool. In the file search tool, Rust regex flavor is used, and [^] does not work there.

You can use

\bMaterials\b[\w\W]*?----\n*

Details:

  • \bMaterials\b - a whole word Materials
  • [\w\W]*? - any zero or more chars as few as possible
  • ---- - a literal string of four hyphens
  • \n* - zero or more line breaks.
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.