'regular expression to copy line with some changes, mirror
I have a code in each html page that I want to duplicate, while add some changes:
Example:
<title>Any text (even if includes :.,</title>
Output:
<title>Any text (even if includes :.,</title>
<meta name="description" content="Any text (even if includes :.,">
In other words, it takes anything in between the title tag, keep the title tag as is, and then add another line for the description tag under that line, that takes whatever inside the title tag (which here is:
Any text (even if includes :.,
which is everything inside the and the tags.
Thanks,
P.S. I use notepdad+ to search and replaxe
Solution 1:[1]
The following regex should match it.
<title>(.*?)</title>
The title's text node will be available in the capturing group with the label 1
.
If your title possibly contains a \n
, then turn on dot matches \n
or swap the .
with [\s\S]
.
Solution 2:[2]
You can use labels like below e.g.
enter code here in find box- <title>(\w*)</title> In replace box- <title>$1</title>\n<meta name="description" content="$1">
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | alex |
Solution 2 | Amit Sood |