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
Posts: 177 Forumite
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!)
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!)
0
Comments
-
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 \/ \/ \/0 -
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.0 -
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 \/ \/ \/0 -
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.0 -
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.0
This discussion has been closed.
Confirm your email address to Create Threads and Reply
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