Is this possible with NP++ & Regex ?

  • Hello ,
    I know that this is way off topic , sorry !
    I have been handed some html documents to apply Regex on.
    Unfortunately I don’t know Regex . so I am hoping that someone here could help me .
    What needs to be done is :
    For each one of these [1] , square brackets with a number inside , surround it with these <b></b> .
    For each one of these [IX] , square brackets with a Roman numeral inside , surround it with these <b></b>
    I have 173 pages of these .
    Thank you very much !.

    <TITLE>WCF Chapter 4</TITLE>
    <!-- HTML by Stephen Pribble -->
    <I>Of Creation</I></H3></CENTER>
    <P ALIGN="LEFT">I. It pleased God the Father, Son, and Holy Ghost,<A NAME="RETURN1"></A><A HREF="#NOTE1">[1]</A> for the manifestation of the glory of his eternal power, wisdom, and goodness,<A NAME="RETURN2"></A><A HREF="#NOTE2">[2]</A> in the beginning, to create, or make of nothing, the world, and all things therein whether visible or invisible, in the space of six days; and all very good.<A NAME="RETURN3"></A><A HREF="#NOTE3">[3]</A>
    <P>II. After God had made all other creatures, he created man, male and female,<A NAME="RETURN4"></A><A HREF="#NOTE4">[4]</A> with reasonable and immortal souls,<A NAME="RETURN5"></A><A HREF="#NOTE5">[5]</A> endued with knowledge, righteousness, and true holiness, after his own image;<A NAME="RETURN6"></A><A HREF="#NOTE6">[6]</A> having the law of God written in their hearts,<A NAME="RETURN7"></A><A HREF="#NOTE7">[7]</A> and power to fulfill it:<A NAME="RETURN8"></A><A HREF="#NOTE8">[8]</A> and yet under a possibility of transgressing, being left to the liberty of their own will, which was subject unto change.<A NAME="RETURN9"></A><A HREF="#NOTE9">[9]</A> Beside this law written in their hearts, they received a command, not to eat of the tree of the knowledge of good and evil;<A NAME="RETURN10"></A><A HREF="#NOTE10">[10]</A> which while they kept, they were happy in their communion with God, and had dominion over the creatures.<A NAME="RETURN11"></A><A HREF="#NOTE11">[11]</A>
    <FONT SIZE="-1">
    <P><A NAME="NOTE1"></A><A HREF="#RETURN1">[1]</A> <B>Hebrews 1:2.</B> Hath in these last days spoken unto us by his Son, whom he hath appointed heir of all things, by whom also he made the worlds. <B>John 1:2-3.</B> The same was in the beginning with God. All things were made by him; and without him was not any thing made that was made. <B>Genesis 1:2.</B> And the earth was without form, and void; and darkness was upon the face of the deep. And the Spirit of God moved upon the face of the waters. <B>Job 26:13.</B> By his spirit he hath garnished the heavens; his hand hath formed the crooked serpent. <B>Job 33:4.</B> The Spirit of God hath made me, and the breath of the Almighty hath given me life.
    <P><A NAME="NOTE2"></A><A HREF="#RETURN2">[2]</A> <B>Romans 1:20.</B> For the invisible things of him from the creation of the world are clearly seen, being understood by the things that are made, even his eternal power and Godhead; so that they are without excuse. <B>Jeremiah 10:12.</B> He hath made the earth by his power, he hath established the world by his wisdom, and hath stretched out the heavens by his discretion. <B>Psalm 104:24.</B> O L<SMALL>ORD</SMALL>, how manifold are thy works! in wisdom hast thou made them all: the earth is full of thy riches. <B>Psalm 33:5-6</B> He loveth righteousness and judgment: the earth is full of the goodness of the L<SMALL>ORD</SMALL>. By the word of the L<SMALL>ORD</SMALL> were the heavens made; and all the host of them by the breath of his mouth.
    <P><A NAME="NOTE3"></A><A HREF="#RETURN3">[3]</A> <B>Genesis 1.</B> <B>Hebrews 11:3.</B> Through faith we understand that the worlds were framed by the word of God, so that things which are seen were not made of things which do appear. <B>Colossians 1:16.</B> For by him were all things created, that are in heaven, and that are in earth, visible and invisible, whether they be thrones, or dominions, or principalities, or powers: all things were created by him, and for him. <B>Acts 17:24.</B> God that made the world and all things therein, seeing that he is Lord of heaven and earth, dwelleth not in temples made with hands.
    <P><A NAME="NOTE4"></A><A HREF="#RETURN4">[4]</A> <B>Genesis 1:27.</B> So God created man in his own image, in the image of God created he him; male and female created he them.
    <P><A NAME="NOTE5"></A><A HREF="#RETURN5">[5]</A> <B>Genesis 2:7.</B> And the L<SMALL>ORD</SMALL> God formed man of the dust of the ground, and breathed into his nostrils the breath of life; and man became a living soul. <B>Ecclesiastes 12:7.</B> Then shall the dust return to the earth as it was: and the spirit shall return unto God who gave it. <B>Luke 23:43.</B> And Jesus said unto him, Verily I say unto thee, To day shalt thou be with me in paradise. <B>Matthew 10:28.</B> And fear not them which kill the body, but are not able to kill the soul: but rather fear him which is able to destroy both soul and body in hell.
    <P><A NAME="NOTE6"></A><A HREF="#RETURN6">[6]</A> <B>Genesis 1:26.</B> And God said, Let us make man in our image, after our likeness: and let them have dominion over the fish of the sea, and over the fowl of the air, and over the cattle, and over all the earth, and over every creeping thing that creepeth upon the earth. <B>Colossians 3:10.</B> And have put on the new man, which is renewed in knowledge after the image of him that created him. <B>Ephesians 4:24.</B> And that ye put on the new man, which after God is created in righteousness and true holiness.
    <P><A NAME="NOTE7"></A><A HREF="#RETURN7">[7]</A> <B>Romans 2:14-15.</B> For when the Gentiles, which have not the law, do by nature the things contained in the law, these, having not the law, are a law unto themselves: Which show the work of the law written in their hearts, their conscience also bearing witness, and their thoughts the mean while accusing or else excusing one another.
    <P><A NAME="NOTE8"></A><A HREF="#RETURN8">[8]</A> <B>Ecclesiastes 7:29.</B> Lo, this only have I found, that God hath made man upright; but they have sought out many inventions.
    <P><A NAME="NOTE9"></A><A HREF="#RETURN9">[9]</A> <B>Genesis 3:6.</B> And when the woman saw that the tree was good for food, and that it was pleasant to the eyes, and a tree to be desired to make one wise, she took of the fruit thereof, and did eat, and gave also unto her husband with her; and he did eat. <B>Ecclesiastes 7:29.</B> Lo, this only have I found, that God hath made man upright; but they have sought out many inventions.
    <P><A NAME="NOTE10"></A><A HREF="#RETURN10">[10]</A> <B>Genesis 2:17.</B> But of the tree of the knowledge of good and evil, thou shalt not eat of it: for in the day that thou eatest thereof thou shalt surely die. <B>Genesis 3:8-11, 23.</B> And they heard the voice of the L<SMALL>ORD</SMALL> God walking in the garden in the cool of the day: and Adam and his wife hid themselves from the presence of the L<SMALL>ORD</SMALL> God amongst the trees of the garden. And the L<SMALL>ORD</SMALL> God called unto Adam, and said unto him, Where art thou? And he said, I heard thy voice in the garden, and I was afraid, because I was naked; and I hid myself. And he said, Who told thee that thou wast naked? Hast thou eaten of the tree, whereof I commanded thee that thou shouldest not eat?... Therefore the L<SMALL>ORD</SMALL> God sent him forth from the garden of Eden, to till the ground from whence he was taken.
    <P><A NAME="NOTE11"></A><A HREF="#RETURN11">[11]</A> <B>Genesis 1:26, 28.</B> And God said, Let us make man in our image, after our likeness: and let them have dominion over the fish of the sea, and over the fowl of the air, and over the cattle, and over all the earth, and over every creeping thing that creepeth upon the earth. And God blessed them, and God said unto them, Be fruitful, and multiply, and replenish the earth, and subdue it: and have dominion over the fish of the sea, and over the fowl of the air, and over every living thing that moveth upon the earth.
    <P><HR WIDTH=60%><CENTER>| <A HREF="wcf03.html">Back</A> | <A HREF="WCF_chapters.html">WCF Index</A> | <A HREF="wcf05.html">Next</A> |</CENTER></BLOCKQUOTE>

  • @vmars-vernon ,

    It’s not off topic, as long as you are expecting Notepad++ regular expressions, and not trying to get us to write you regex that you’ll be using in some other tool, and then complaining when a perfectly good Notepad++ regex doesn’t work in your other tool.

    Your history shows it’s been about a year since your last regex/search-replace question (based on topic titles), so you’re also obviously not just trying to frequently abuse this forum as your personal regex writing service like some users try. But we do ask that after we give you a regex that you try to learn from the example, and give future regex attempts a go yourself, and show what you tried if you are having difficulty.

    Hopefully, you will learn more about regex from this example. The only way to learn is to read the docs, experiment, and ask meaningful questions.

    Thanks for including your sample data in the </>-plain-text mode. It would’ve been nice to include an example of [IX] in context as well, to make sure. Because of that, I wrote my own sample data, rather than using yours.

    One of the difficulties of your search is that you want to match [ and ], which have special meaning in regex, so you have to escape them. And, even worse, showing the escaped versions of that character in this forum can be hard to do, depending on circumstance. So instead of using that character, I will use an equivalent sequence which I will explain below.

    My process: “I want to look for text which starts with [, contains either one or more decimal digits or contains valid roman numeral characters (I,V,X,L,C,D,M), followed by ]”. (Note, I am not going to check for valid roman numerals, just for a sequence of roman numeral characters)

    I then translate each of those pieces: [ can be matched using \x5b, and ] matched by \x5d. The “contains either or” can be accomplished with the idiom (...|...). “one or more decimal digits” is \d+. “one or more roman numeral characters” is [IVXLCDM]+. I will also prefix (?-i) to make the match case-sensitive, since roman numerals are generally upper case, especially in the Biblical chapter numbering context your sample data uses. Bring those all together into (?-i)\x5b(\d+|[IVXLCDM]+)\x5d

    In the replacement, you want to surround the whole match by bold tags. The $0 supplies the “value of the whole matched text”, so <b>$0</b> will surround the matched text with bold markup.

    in my example data

    [CXIX] [176]

    using FIND = (?-i)\x5b(\d+|[IVXLCDM]+)\x5d, REPLACE = <b>$0</b>, MODE = regular expression, REPLACE ALL gave me:

    <b>[CXIX]</b> <b>[176]</b>

    Good luck

    Oh, and if you’ve already changed some but not all, if you start over, it will mess up, because the [1] inside <b>[1]</b> still matches, so it would become <b><b>[1]</b></b> a second time around. So either just do a single REPLACE ALL per file, or if you need to be able to exclude bracketed digits or roman numerals that are already bold, the regex will have to be edited.


    Do you want regex search/replace help? Then please be patient and polite, show some effort, and be willing to learn; answer questions and requests for clarification that are made of you. All example text should be marked as literal text using the </> toolbar button or manual Markdown syntax. To make regex in red (and so they keep their special characters like *), use backticks, like `^.*?blah.*?\z`. Screenshots can be pasted from the clipboard to your post using Ctrl+V to show graphical items, but any text should be included as literal text in your post so we can easily copy/paste your data. Show the data you have and the text you want to get from that data; include examples of things that should match and be transformed, and things that don’t match and should be left alone; show edge cases and make sure you examples are as varied as your real data. Show the regex you already tried, and why you thought it should work; tell us what’s wrong with what you do get. Read the official NPP Searching / Regex docs and the forum’s Regular Expression FAQ. If you follow these guidelines, you’re much more likely to get helpful replies that solve your problem in the shortest number of tries.

  • Thanks Peter ,
    I am sorry to report that today I am that guy
    “abuse this forum as your personal regex writing service like some users try” .
    I am working on a “KidSafeBrowser” in ‘Electron js’ and another one as a chrome extension for my grandkids .
    link text
    A friend asked me to do this Regex stuff .
    As usual , Thank You for all your work on this .
    I created a desktop Folder , and named it ‘Regex Peter Jones’ and
    put you work in there . I do plan to learn Regex , just can’t now .
    Thanks , Vern

Log in to reply