We’d like to remind Forumites to please avoid political debate on the Forum.

This is to keep it a safe and useful space for MoneySaving discussions. Threads that are – or become – political in nature may be removed in line with the Forum’s rules. Thank you for your understanding.

📨 Have you signed up to the Forum's new Email Digest yet? Get a selection of trending threads sent straight to your inbox daily, weekly or monthly!
The Forum now has a brand new text editor, adding a bunch of handy features to use when creating posts. Read more in our how-to guide

Find and Replace Utility. Regular Expressions. Wildcards.

paulstar
paulstar Posts: 177 Forumite
edited 21 August 2016 at 12:09PM in Techie Stuff
I'm using an (excellent) program called fnr.exe. It opens files (.htms in my case) in a folder and finds and replaces text within the files. I have files containing text of this nature:

Camping in 2016 France
Camping in 2017 France
Camping in 2018 France
Camping in 2019 France

which I want to change to:

Caravanning in 2016 Italy
Caravanning in 2017 Italy
Caravanning in 2018 Italy
Caravanning in 2019 Italy

With the "Use regular Expressions" box ticked, fnr.exe finds all of these with the Find string Camping in 201?[0-9] France.

But what do I put in the Replace field? I've tried loads of variations such as Caravanning in 201? Italy but it refuses to copy the variable digit (6, 7, 8, 9) and I end up with "Caravanning in 201? Italy" in every file.

How do I get it to copy the variable digit - the wildcard - across?

(I can't do two replaces, one for "Camping in 201" and another for "France", as France appears elsewhere in the text and must not be changed. I actually have a lot more than 4 strings to do!)

Comments

  • Strider590
    Strider590 Posts: 11,874 Forumite
    It does what?

    Does it replace file names? or does it open text files and change text within?

    Both are completely different.


    And what about file extensions?
    “I may not agree with you, but I will defend to the death your right to make an a** of yourself.”

    <><><><><><><><><<><><><><><><><><><><><><> Don't forget to like and subscribe \/ \/ \/
  • paulstar
    paulstar Posts: 177 Forumite
    Strider590 wrote: »
    It does what?

    Does it replace file names? or does it open text files and change text within?

    Both are completely different.


    And what about file extensions?

    It opens files and changes text within. I'm using it on .htm files. I've edited the OP to include this clarification.
  • Strider590
    Strider590 Posts: 11,874 Forumite
    edited 21 August 2016 at 12:24PM
    Ok, so instead try doing it individually for every year and do the process several times instead of once. In other words do away with the wildcard thing.

    The other option depending on how many files, is to open them all in Notepad and do it manually with CTRL+H, just type "camping" in the top box and "caravanning" in the lower box and watch it go, it wouldn't take very long at all unless you've got 1000 files to edit.
    “I may not agree with you, but I will defend to the death your right to make an a** of yourself.”

    <><><><><><><><><<><><><><><><><><><><><><> Don't forget to like and subscribe \/ \/ \/
  • SalsaDanca
    SalsaDanca Posts: 434 Forumite
    Part of the Furniture 100 Posts
    edited 21 August 2016 at 12:31PM
    You can use the $ sign to refer to different parts of the text that matched the regular expression that you used in your search. Have a look at these webpages:

    https://msdn.microsoft.com/en-us/library/az24scfc(v=vs.110).aspx#substitutions

    https://msdn.microsoft.com/en-us/library/ewy2t5e0(v=vs.110).aspx

    It's a long time since I've used regular expressions for this type of thing, so I can't tell you exactly how to do it. It might be as simple as "Caravanning in 201$1 in Italy", or you might need to experiment a bit to find the right solution.
  • paulstar
    paulstar Posts: 177 Forumite
    SalsaDanca wrote: »
    You can use the $ sign to refer to different parts of the text that matched the regular expression that you used in your search. Have a look at these webpages:

    https://msdn.microsoft.com/en-us/library/az24scfc(v=vs.110).aspx#substitutions

    https://msdn.microsoft.com/en-us/library/ewy2t5e0(v=vs.110).aspx

    It's a long time since I've used regular expressions for this type of thing, so I can't tell you exactly how to do it. It might be as simple as "Caravanning in 201$1 in Italy", or you might need to experiment a bit to find the right solution.

    Salsa, you're a star.

    Find Camping in 201(\d+) France Replace Caravanning in 201$1 Italy worked like a charm.

    Very much appreciated, thank you.
This discussion has been closed.
Meet your Ambassadors

🚀 Getting Started

Hi new member!

Our Getting Started Guide will help you get the most out of the Forum

Categories

  • All Categories
  • 353.6K Banking & Borrowing
  • 254.2K Reduce Debt & Boost Income
  • 455.1K Spending & Discounts
  • 246.6K Work, Benefits & Business
  • 603K Mortgages, Homes & Bills
  • 178.1K Life & Family
  • 260.6K Travel & Transport
  • 1.5M Hobbies & Leisure
  • 16K Discuss & Feedback
  • 37.7K Read-Only Boards

Is this how you want to be seen?

We see you are using a default avatar. It takes only a few seconds to pick a picture.