How to get pure code line number for a *.vhd file?
-
I found a very interesting topic on the post: Deleting full words after certain length (after 36 char) that really show how powerful a regression expression is. I consider learning it sometimes later.
Terry R: You could try the following using the Replace function.
Find What:(?-s)^(?=.{37,})(.{1,36})\s.*
Replace With:$1Each line in a VHDL file that starts with “–” or empty, excluding leading space characters, is counted as a none code line.
Currently, Norepad++ shows a file’s full line number.I want 1 regression expression: a regression expression to generate pure code lines’ number for a *.vhd file.
Based on the regression expression statement, I may learn the language to write a statement to
generate all pure code files in all opened VHDL files.Can you recommend some books to learn regression expression language?
Thank you.
-
@W-TX ,
Can you recommend some books to learn regression expression language?
You have been in this forum for more than two years now. You must by now know that there’s a FAQ section. You must have seen that that FAQ section has an entry on regular expression resources. Please go re-familiarize yourself with that FAQ Desk entry.
(And FYI, “regex” is short for “regular expression”, not “regression expression”.)
expression to generate pure code lines’ number for a *.vhd file.
The flavor of regex that Notepad++ uses does not know how to count (that it, it does not have an incrementing counter that can be used in replacements), so there is no such regex.
However, using one of the scripting language (like PythonScript) it’s really easy to combine the power of a programming language (like Python), including their ability to increment variables, with regular expressions, and use those together on the contents of the file(s) open in Notepad++. If you search the forum for
add_1
, you will see plenty of examples for how to use PythonScript to solve similar replace-with-increasing-number problems, and you should be able to figure out how to change the regex in those example to match only the lines you want to count.----
Please note: This Community Forum is not a data transformation service; you should not expect to be able to always say “I have data like X and want it to look like Y” and have us do all the work for you. If you are new to the Forum, and new to regular expressions, we will often give help on the first one or two data-transformation questions, especially if they are well-asked and you show a willingness to learn; and we will point you to the documentation where you can learn how to do the data transformations for yourself in the future. But if you repeatedly ask us to do your work for you, you will find that the patience of usually-helpful Community members wears thin. The best way to learn regular expressions is by experimenting with them yourself, and getting a feel for how they work; having us spoon-feed you the answers without you putting in the effort doesn’t help you in the long term and is uninteresting and annoying for us.
----
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 formatting commands.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 usingCtrl+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.
-
Even though I posted a question about Regex yesterday, I really started the job and try to resolve the problem myself: https://en.wikipedia.org/wiki/Regular_expression using Regex.
-
@PeterJones said in How to get pure code line number for a *.vhd file?:
The flavor of regex that Notepad++ uses does not know how to count (that it, it does not have an incrementing counter that can be used in replacements), so there is no such regex.
No. It can!
What I need to do is to delete “\n” for comment lines that start with “–”, excluding leading space characters, and empty lines.
The resulting file becomes a new *.vhd file and Notepad++ shows its line number in the status bar!
-
@W-TX
Here is exactly what I want to do:
Search for “\n” for comment lines that start with “–”, excluding leading space characters, and empty lines.
Replace with a space.After the Notepad++ shows the changed file’s line number, the pure code line number, click undo icon to return to prior status.