Hello Mr. Nisus,
I am very happy to have found a word processor as easy manageable as Text Edit, with sophisticated stuff like Regex.
But I could not find a solution yet how to change ONE attribute at a time, for example Color. I have a text with read headlines that should get a somehow darker appearance. They all differ in fontsize and even font etc, but have the same color: some certain sort of RED.
Is it also possible to find a RANGE OF COLORS, like all shades of red, in the same search phrase?
Would you please give me some hints?
I feel quite fluent in Regexeese.
Also I would like to give notice of some things that do not behave as expected. Where should I report them?
with greetings from Europe
WiLi
change color by regex
- martin
- Official Nisus Person
- Posts: 5230
- Joined: 2002-07-11 17:14:10
- Location: San Diego, CA
- Contact:
Re: change color by regex
Hello WiLi,
If you were only searching for an exact shade of red (ie: the color you want to match is exactly the same in each case) this is quite easy: just apply the formatting to your find pattern (regex), and Nisus Writer will automatically engage the "attribute sensitive" option in the Find & Replace dialog. This works for any attributes, whether it be font, character styles, colors, etc. Just select your find pattern and use the menus to apply the formatting criteria.
If you want to change the formatting for some matches, you could use the attribute sensitive replacement mode, but I find it easier to simply do a Find All (which selects all the matching text), and then format it using the menus, palettes, etc, as normal.
However, it sounds like you're interested in not simply matching a single exact shade of red, but rather all colors that appear reddish. This is a trickier problem to solve, because you can't really define that using a regex. Well, if you were desperate I suppose you could do a pattern like ".+|.+|.+|.+|..." where each ".+" had a different shade of red applied, but that's a horrible solution and not entirely feasible with colors, where you have so many possible values. Instead, it's easier to use a macro for this.
The attached macro will do something like you ask– fuzzy matching all text that appears reddish. It manually iterates all text in the document, inspecting each attribute run individually. Wherever the formatting passes the test set forth by the "ShouldMatchAttributes" sub function/command, the corresponding text will be selected.
I hope that helps. Let me know if you have any questions.
Excellent, we're glad to have you, and to hear of your happiness!WiLi wrote:I am very happy to have found a word processor as easy manageable as Text Edit, with sophisticated stuff like Regex.
This is definitely possible. How you accomplish it will depend on what you need exactly.But I could not find a solution yet how to change ONE attribute at a time, for example Color. I have a text with read headlines that should get a somehow darker appearance. They all differ in fontsize and even font etc, but have the same color: some certain sort of RED.
Is it also possible to find a RANGE OF COLORS, like all shades of red, in the same search phrase?
If you were only searching for an exact shade of red (ie: the color you want to match is exactly the same in each case) this is quite easy: just apply the formatting to your find pattern (regex), and Nisus Writer will automatically engage the "attribute sensitive" option in the Find & Replace dialog. This works for any attributes, whether it be font, character styles, colors, etc. Just select your find pattern and use the menus to apply the formatting criteria.
If you want to change the formatting for some matches, you could use the attribute sensitive replacement mode, but I find it easier to simply do a Find All (which selects all the matching text), and then format it using the menus, palettes, etc, as normal.
However, it sounds like you're interested in not simply matching a single exact shade of red, but rather all colors that appear reddish. This is a trickier problem to solve, because you can't really define that using a regex. Well, if you were desperate I suppose you could do a pattern like ".+|.+|.+|.+|..." where each ".+" had a different shade of red applied, but that's a horrible solution and not entirely feasible with colors, where you have so many possible values. Instead, it's easier to use a macro for this.
The attached macro will do something like you ask– fuzzy matching all text that appears reddish. It manually iterates all text in the document, inspecting each attribute run individually. Wherever the formatting passes the test set forth by the "ShouldMatchAttributes" sub function/command, the corresponding text will be selected.
I hope that helps. Let me know if you have any questions.
The best way to report bugs and issues to us directly is from inside Nisus Writer itself by using the menu Help > Send Feedback.Also I would like to give notice of some things that do not behave as expected. Where should I report them?
- Attachments
-
Match By Custom Function.nwm
- (22.67 KiB) Downloaded 341 times
Re: change color by regex
Hello Martin,
I was aware that a Regex search formula can get attributes attached by selecting them: bold, Fontsize, color etc. But how do I ONLY allocate the color (red) and NOT Fontsize and other text attributes at the same time? How can I deselect those other attributes?
Thank you for your fast and concise response! I will still have to study your sample.
The Bug Reporting does not work at the moment, maybe the url does not work. I will send an email instead.
I could as well write the reports here in the forum, if you prefer.
greetings
WiLi
I was aware that a Regex search formula can get attributes attached by selecting them: bold, Fontsize, color etc. But how do I ONLY allocate the color (red) and NOT Fontsize and other text attributes at the same time? How can I deselect those other attributes?
Thank you for your fast and concise response! I will still have to study your sample.
The Bug Reporting does not work at the moment, maybe the url does not work. I will send an email instead.
I could as well write the reports here in the forum, if you prefer.
greetings
WiLi
- martin
- Official Nisus Person
- Posts: 5230
- Joined: 2002-07-11 17:14:10
- Location: San Diego, CA
- Contact:
Re: change color by regex
By default the attributes in the find/replace fields are neutral (ie: they will match any font, size, etc). Of course the text in those fields must display in some font, so NWP shows your default/document font, but that doesn't mean the matching will be restricted to that font. This neutral state is indicated by having the menu Format > Any Attributes shown as check-marked. If one or more attributes have been applied to the find expression that menu will not be check-marked.WiLi wrote:I was aware that a Regex search formula can get attributes attached by selecting them: bold, Fontsize, color etc. But how do I ONLY allocate the color (red) and NOT Fontsize and other text attributes at the same time? How can I deselect those other attributes?
If you want to clear out one or more attributes applied to your find expression, you need only use the "Any Attributes" menu or the commands that clear individual attributes, eg: using the menu Format > Size > Any Font Size will remove any font attribute applied to the selected find expression.
I hope that makes sense.
I just tried the feedback reporter inside NWP and it's working for me. What error are you seeing?The Bug Reporting does not work at the moment, maybe the url does not work. I will send an email instead.
I could as well write the reports here in the forum, if you prefer.
Where you'd like to report errors is up to you. The feedback reporter is the best for us because it can automatically gather recent log files, which are invaluable when diagnosing crashes and other kinds of more technical errors. However, if you just have an easily reproducible misbehavior or feature request to report, emailing directly works well. Or if you think the issue would benefit from a public discussion, then posting on the forums may be best.
- martin
- Official Nisus Person
- Posts: 5230
- Joined: 2002-07-11 17:14:10
- Location: San Diego, CA
- Contact:
Re: change color by regex
I should mention one other method of reporting errors to us, if the feedback reporter is not working:
1. Open the feedback reporter in NWP.
2. Fill it out as normal.
3. Instead of transmitting it directly, save it using the "Save Report" button.
4. Email us the saved report/archive.
1. Open the feedback reporter in NWP.
2. Fill it out as normal.
3. Instead of transmitting it directly, save it using the "Save Report" button.
4. Email us the saved report/archive.
Re: change color by regex
Thank you very very much, Martin,
this works.
The method of choice is: define a search / Power Search / Power Search Pro (Regex), then SELECT ALL of the search term, then reset all formatting by Format > Any Attributes, then reassign an attribute by selecting the special attribute you want to search for (in my case select the text color) and perform the search.
Define the Replace Term in just the same manner (here with a modified color) and do the Replace. Voila.
WiLi
this works.
The method of choice is: define a search / Power Search / Power Search Pro (Regex), then SELECT ALL of the search term, then reset all formatting by Format > Any Attributes, then reassign an attribute by selecting the special attribute you want to search for (in my case select the text color) and perform the search.
Define the Replace Term in just the same manner (here with a modified color) and do the Replace. Voila.
WiLi
Re: change color by regex
Reports:
One "not expected behaviour" of a regex search has been sorted out by me, it was due to my assumption that Regex in NWP sees a return character as "\r", but in reality it is "\n" (new line) instead.
Maybe you know something to say to my other problem as well:
I wanted to do some editing on a html code that was produced by my OCR program that scanned a book and was astonished that NWP offers to open the html document, and render it somehow equivalent to a web browser.
But the text that was readable normally in a browser appears as a very narrow column of text, sometimes only as wide as a single character (in a big font size).
Text Edit from Apple behaves somehow similar, but Dreamweaver or Ultra Edit display the text as expected. The drawbacks are: DW is very slow and UE is missing Regex.
I helped myself by just doing code modifications with an other text editor that was capable of Regex and confirm the changes in the web browser.
It would be nice to one day be able to use NWP for this task also.
Thank you for your assistance!
WiLi
One "not expected behaviour" of a regex search has been sorted out by me, it was due to my assumption that Regex in NWP sees a return character as "\r", but in reality it is "\n" (new line) instead.
Maybe you know something to say to my other problem as well:
I wanted to do some editing on a html code that was produced by my OCR program that scanned a book and was astonished that NWP offers to open the html document, and render it somehow equivalent to a web browser.
But the text that was readable normally in a browser appears as a very narrow column of text, sometimes only as wide as a single character (in a big font size).
Text Edit from Apple behaves somehow similar, but Dreamweaver or Ultra Edit display the text as expected. The drawbacks are: DW is very slow and UE is missing Regex.
I helped myself by just doing code modifications with an other text editor that was capable of Regex and confirm the changes in the web browser.
It would be nice to one day be able to use NWP for this task also.
Thank you for your assistance!
WiLi
- martin
- Official Nisus Person
- Posts: 5230
- Joined: 2002-07-11 17:14:10
- Location: San Diego, CA
- Contact:
Re: change color by regex
We use Apple's HTML importer for this task, so it's not too surprising that TextEdit should show you a similar representation of the file. From what you describe, it may be that the text has very large left/right indents applied, or perhaps is contained inside a very narrow table cell. If you send us the file via email we'd be happy to take a look. There may be nothing we can do to improve the HTML import, but at least we could advise you on how to best handle the text once it's inside Nisus Writer.WiLi wrote:But the text that was readable normally in a browser appears as a very narrow column of text, sometimes only as wide as a single character (in a big font size).
Text Edit from Apple behaves somehow similar