How to add a blank space and a word before every comma in some meta tags in every html file of a folder?
-
@guy038 I have understood this much:
$0 Inserts all text matched in the regex (automatic unnamed capture)
and\x20
adds a space,g
searches for a string repeatedly. The rest is still “Latin” and “Greek” to me. I, therefore, request you to help find the wordcure
wherever it appears in the META tag (not just in the first line) so that I can replace it. -
@Ramanand-Jhingade said in How to add a blank space and a word before every comma in some meta tags in every html file of a folder?:
The rest is still “Latin” and “Greek” to me. I, therefore, request you to help
Thank you for trying to understand. But like learning Latin and Greek, you cannot expect to be an expert in regex in one afternoon. But just because you’re not a Latin/Greek expert doesn’t give you permission to go into a forum on ancient texts and ask them to translate a manuscript you just found, for free, on your terms and on your timeline. When they point you to courses or websites on learning ancient Latin and Greek, you are expected to then go avail yourself of that documentation and give it a shot yourself.
Guy gave you the formula for “change X into Y, but only when it’s between START and END” (using “FR”, “RR”, “BSR”, “ESR”). And he even gave you the first version of what those markers should be, based on your data. Try applying what you learned. If you get stuck, show us what you tried and why you thought it would work, an example of the data input, and how the output differs from what you expected.
Instead, you give a one sentence of “I tried something, and it didn’t work, so just do it for me”, which is an attitude not appreciated here.
Guy will likely come back and hand you yet another answer, and that’s his prerogative. But until you start trying to learn this, it’s going to remain foreign to you, and you’re going to continue to struggle.
Also understand: a lot of what people think are going to be “easy” search-and-replace requests are actually very involved. The “change X into Y, but only when it’s between START and END” sounds easy, but the answer is complicated; that’s why Guy went to the trouble of figuring out the generic formula for that request, which is about as plug-and-play as a regex gets. But sometimes, you are going to have to try various things on your own until you figure it out.
This forum is not a do-my-data-manipulation-for-me-for-free location. We point people to initial answers about regex to inform them that Notepad++'s regex can do a lot, and that if they invest the time in learning regex, they will be able to eventually figure out how to do their own data manipulation for themselves.
-
Hi, @ramanand-jhingade, @peterjones and All,
To @peterjones :
I fully support what you said to @ramanand-jhingade. However, I considered that my previous post could be worth to, as it gave, from the same generic regex S/R adapted to mono-lines search, described below, two different solutions for two different goals !
SEARCH
(?-s)(?-i:
BSR|(?!\A)\G).*?\K(?-i:
FR)
REPLACE RR
where :
-
BSR is the Begin Search-region Regex expression to search BEFORE any FR string located in current line
-
FR is the Find Regex expression, which may be present once or several times in current line
-
RR is the Replace Regex expression, which replaces any FR expression found in current line
To @ramanand-jhingade :
-
The
(?-i:This is a Text)
syntax is a non-capturing group which searches for the exact stringThis is a Text
-
The
(?i:This is a Text)
syntax is a non-capturing group which searches for the stringThis is a Text
whatever its case. For instance, this regex may find any of these expressions :-
This is a Text
-
this is a text
-
This Is A Text
-
tHIs iS a teXT
-
THIS IS A TEXT
-
-
Similarly, the
(?-i)(This is a Text)
syntax is a capturing group which searches for the exact stringThis is a Text
-
The
(?i)(This is a Text)
syntax is a capturing group which searches for the stringThis is a Text
whatever its case. For instance, this regex may find any of these expressions :-
this is A TEXT
-
THIS IS a text
-
ThIs Is A TeXt
-
You also said :
g
searches for a string repeatedlyNot exactly ! We’re are speaking about the
\G
assertion ( i.e. a condition ) which is TRUE only if the present match IMMEDIATELY follows the previous match !. For instance, let’s imagine the regex\Ga
against the text, below, in a new tabaaaaaabaaaaaaa aaaaaabaaaaaaa
-
Move the cursor at the very beginning (
Ctrl + Home
) -
Search
\Ga
-
Hit repeatedly on the Find Next button
=> As you can see, it will match any
a
letter and stop when meeting theb
letter. Logical, as the nexta
char, so the future match, does not immediately follows the previousa
letter-
Now, move the caret right after the
b
letter. Again, anya
letter is matched but note that it stops after the last char of the first line. Again, this behaviour is logical as, between the lasta
and the nexta
, there are the two Windows line-break chars (CR
andLF
). So, the two matches are not consecutive ! -
And, if you move the caret at beginning of the second line, again, the regex engine will match any
a
letter till theb
letter !
I must admit that the
\G
assertion, even when explained, is not easy to handle ! At least, much less than the usual^
and$
assertions which match the zero-length locationsBeginning
andEnd
of current line !But modifiers, non-capturing and capturing groups are well explained in most of regex tutorials ! So, no matter, you need to
"read this fucking manual"
!!You will probably be disappointed by your first attempts but you will progress ! No doubt about it !
Best Regards,
guy038
-
-
@guy038 You are talking of what is available here: Notepad User Manual right?
-
@Ramanand-Jhingade said in How to add a blank space and a word before every comma in some meta tags in every html file of a folder?:
You are talking of what is available here: Notepad User Manual right?
Yes. Specifically, as I posted earlier:
Read the official NPP Searching / Regex docs and the forum’s Regular Expression FAQ.
-
Yes and more precisely :
-
https://npp-user-manual.org/docs/searching/ about the general concept of searching
-
https://npp-user-manual.org/docs/searching/#regular-expressions about regular expressions
A valuable site (and the reference !) is that one, too ( not especially devoted to the
Boost
regex library, used within N++ ) :And begin with https://www.regular-expressions.info/quickstart.html
Of course, you need two weeks, minimum, to feel at ease with simple goals and, let’s say, three months to become fluent to regex syntaxes in order to modify
90 %
texts as you want to, about. For the remaining10 %
you’re welcome and we’ll probably find out a suitable solution !Note that, with the knowledge of basic regexes syntax, the provided solutions should enlighten you much better than at present, without the necessary background !
BR
guy038
-
-
@guy038 I was able to do what I wanted by using this Regex in the “Find All” field:
(?-s)(?-i:<META\x20|(?!\A)\G).*?\Kcure
and thiscure\x20for
in the “Replace in Files” field. Thanks for the idea. Now, a lot of people will find this page through search engines, so just for their convenience and information please do let us know how to search for more than one string of characters and add a word with a space to the end of that string but where the search is limited to the Meta tags (it should not search the rest of the file) -
@guy038 This:-
SEARCH(?-s)(?-i:<META\x20|(?!\A)\G).*?\K(?-i:Homeopathic (treatment|doctor|clinic|specialist)|Homeopathy)
REPLACE ALL
$0\x20for
did not work for me! -
How about this bro?
-
@Reza-Saputra I already searched for each word individually and replaced each with the code I posted for searching for the word, “cure” which was originally given by @guy038 that is
(?-s)(?-i:<META\x20|(?!\A)\G).*?\Kcure
and thiscure\x20for
However, I can tell you thath
findsone horizontal whitespace character: tab or Unicode space separator
that is it! -
Hello, @ramanand-jhingade,
You said :
please do let us know how to search for more than one string of characters and add a word with a space to the end of that string but where the search is limited to the Meta tags (it should not search the rest of the file)
Well, from the two parts of this previous post and from what I specifically wrote to @peterjones, here, you should had guessed how to do it !
Indeed, from the generic regex :
SEARCH
(?-s)(?-i:
BSR|(?!\A)\G).*?\K(?-i:
FR)
REPLACE RR
where :
-
BSR is the Begin Search-region Regex expression to search BEFORE any FR string located in current line
-
FR is the Find Regex expression, which may be present once or several times in current line
-
RR is the Replace Regex expression, which replaces any FR expression found in current line
we can build up the suitable regex in order to look for, let’s say,
4
different wordsWord_1
,Word_2
,Word_3
andWord_4
, inmeta
tags only, written in a single line and add, after each of them, the wordWORD
!-
BSR ( Begin Search-region Regex ) =
<META\x20
-
FR ( Find Regex ) = Word_1
|
Word_2|
word_3|
Word_4 -
RR ( Replace Regex ) =
$0\x20
WORD
leading to the right regex S/R :
SEARCH
(?-s)(?-i:<META\x20|(?!\A)\G).*?\K(?-i:Word_1|Word_2|word_3|Word_4)
REPLACE
$0\x20
WORD
Now, you said :
SEARCH
(?-s)(?-i:<META\x20|(?!\A)\G).*?\K(?-i:Homeopathic (treatment|doctor|clinic|specialist)|Homeopathy)
REPLACE
$0\x20for
did not work for me!
Well, may be try this one :
SEARCH
(?-s)(?-i:<META\x20|(?!\A)\G).*?\K(?-i:Homeopathic\h+(treatment|doctor|clinic|specialist)|Homeopathy)
REPLACE
$0\x20for
If it does not work either, just send me your file by e-mail. Refer to this post, to get my temporary e-mail address !
BR
guy038
-
-
@guy038 I already searched for each word individually and replaced each with the code you posted here first to search for the META tag and comma. I used it to search for the word, “Homeopathy”, with this RegEx:
(?-s)(?-i:<META\x20|(?!\A)\G).*?\KHomeopathy
and replaced it with this:Homeopathy\x20for
so I will not bother you again.
I am glad you replied - I think you realised that doing this is was beyond my present abilities and comprehension! -
Just an FYI a good place to learn regex and test your code is regex101.com
-
@Acme1235 said in How to add a blank space and a word before every comma in some meta tags in every html file of a folder?:
Just an FYI a good place to learn regex and test your code is regex101.com
… which is linked to in the Regular Expression FAQ that we have repeatedly asked Ramanand to read.