• Matching Phone Numbers

    7
    0 Votes
    7 Posts
    684 Views
    Terry RT

    @arthur-schwarez said in Matching Phone Numbers:

    I don’t know if notepad++ is suitable for this purpose.

    In this case I’d say it is suitable.

    We have people asking in this forum for a solution so it makes sense to provide that within the context of using Notepad++, if possible. Certainly sometimes there are applications elsewhere which may do the task just as well, sometimes even better. However it would likely mean the person asking will need to learn yet another thing, something they may not need to ever use again. At least a Notepad++ based solution offers the person asking, some ideas on how Notepad++ may help them with ever increasing complex issues.

    So whilst we try to keep to the Notepad++ theme, solution providers here will sometimes suggest an alternative, especially where Notepad++ is definitely not the best platform.

    Terry

  • 0 Votes
    5 Posts
    2k Views
    Alan KilbornA

    So this critical shortcoming in Notepad++ has come up many times before, and probably even more times than I list here:

    https://community.notepad-plus-plus.org/topic/14644 https://community.notepad-plus-plus.org/topic/15606 https://community.notepad-plus-plus.org/topic/20519 https://community.notepad-plus-plus.org/topic/20584 https://community.notepad-plus-plus.org/topic/20586 https://github.com/notepad-plus-plus/notepad-plus-plus/issues/94 https://github.com/notepad-plus-plus/notepad-plus-plus/issues/760 https://github.com/notepad-plus-plus/notepad-plus-plus/issues/5113 https://github.com/notepad-plus-plus/notepad-plus-plus/issues/8450 https://github.com/notepad-plus-plus/notepad-plus-plus/issues/9584 https://github.com/notepad-plus-plus/notepad-plus-plus/issues/10012

    A few times before when I’ve seen such postings, I’ve thought about sharing my PythonScript method for solving it, but, well, sometimes you have something nice that works for you, but to share it you have to put more “shine” on it. This time I’ve attempted to do that, and I’ve shared the cleaned-up script below.

    Aside: In my response to one of the Community threads above, I see that I promised to post something “soon”. Well, that was back in January of 2021, so “soon” is relative. :-)

    The script works on multiple selection types:

    a normal single stream selection (but why? Just use Notepad++'s own Replace All) column-block selection (the issue posed by the OP to this thread) multiple stream selections (that have been selected with the “Multi-editing” feature of Notepad++ turned on):
    Imgur

    The script is fairly simple to use. Make your selection(s) and then run the script. You will be prompted through a series of dialog boxes to provide your parameters for the replacement operation:

    specifying what you want to find:
    Imgur

    specifying what you want to replace the found matches with:
    Imgur

    specifying other options, like case sensitivity, regular expression mode, etc.:
    Imgur
    To use the options, you put an x inside the brackets in front of an option you want to select; example to select case sensitivity:
    Imgur

    After everything has been specified, press OK and the replacement(s) will be made in the active selection(s).

    If you have chosen the “pre-replace-count-preview” option, you will get a prompt like this before the document text is changed:
    Imgur
    Choosing Yes from there will do the replacing without further prompt.
    Choosing No will result in an additional prompt:
    Imgur

    If you have selected the “post-replacement-summary” option, after replacements have been made, you will see a box like this appear:
    Imgur

    That’s it; here’s the listing for the script, ReplaceAllInSelections.py:

    # -*- coding: utf-8 -*- from Npp import * import re import inspect class RAIS(object): def __init__(self): self.script_name = inspect.getframeinfo(inspect.currentframe()).filename.split('\\')[-1] self.remembered_find_regex_str = '' self.remembered_repl_regex_str = '' self.remembered_case_sens_setting = False self.remembered_whole_word_setting = False self.remembered_regex_setting = False self.remembered_pre_repl_preview_setting = False self.remembered_post_repl_summary_setting = False self.help_str = ''' HELP pre-replace-preview : pops up a box BEFORE replacements are made, telling how many there will be; at that point there will be a way to cancel so that the replacements aren't made; and a way to leave the matches selected post-replace-summary : pops up a box after replacements are made, telling how many were made ''' def mb(self, msg, flags=0, title=''): if len(title) == 0: title = self.script_name return notepad.messageBox(msg, title, flags) def custom_rereplace(self, find_what, replace_with, ignore_case_flag=0, max_num_of_replacements=0, start_end_pos_tup=None): # if start_end_pos_tup is None, replace will be done in all active selections leave_caret_here = None start_end_pos_tup_list = [] if start_end_pos_tup == None: if editor.getSelectionEmpty(): start_end_pos_tup_list.append((0, editor.getTextLength())) leave_caret_here = editor.getCurrentPos() else: for n in range(editor.getSelections()): (s, e) = (editor.getSelectionNStart(n), editor.getSelectionNEnd(n)) append_it = True if 1: # prevent, e.g., a regex search for ^ from replacing "outside" a column-block's visual region # (could happen on empty lines inside the block) if editor.getSelectionNAnchor(n) <= editor.getSelectionNCaret(n): if editor.getSelectionNAnchorVirtualSpace(n) > 0: append_it = False else: if editor.getSelectionNCaretVirtualSpace(n) > 0: append_it = False if append_it: start_end_pos_tup_list.append((s, e)) start_end_pos_tup_list.sort() else: start_end_pos_tup_list.append(start_end_pos_tup) running_offset = 0 first = True if editor.selectionIsRectangle(): # get out of column selection mode as it messes up trying to correctly set selections later editor.setEmptySelection(editor.getCurrentPos()) for (s, e) in start_end_pos_tup_list: s_plus_ro = s + running_offset e_plus_ro = e + running_offset old_len = editor.getLength() editor.rereplace(find_what, replace_with, ignore_case_flag, s_plus_ro, e_plus_ro, max_num_of_replacements) new_len = editor.getLength() if leave_caret_here == None: new_sel_end = e_plus_ro + new_len - old_len if first: editor.setSelection(new_sel_end, s_plus_ro) else: editor.addSelection(new_sel_end, s_plus_ro) running_offset += new_len - old_len first = False if leave_caret_here != None: editor.setEmptySelection(leave_caret_here) def run(self): editor.setMultipleSelection(True) line_ending = ['\r\n', '\r', '\n'][editor.getEOLMode()] num_selections = editor.getSelections() # editor.getSelText() returns...: # skinny caret rect block always returns '' # non-skinny rect block returns line data separated by line-endings # non-skinny rect block totally in virtual space returns only line-endings # example: 3-line rect block in virtual space in windows file returns '\r\n\r\n\r\n' # non-rect multiple-selection text is returned contiguously with no delimiters of any type between! if editor.selectionIsRectangle(): if len(editor.getSelText()) <= num_selections * len(line_ending): self.mb('No text in rectangular selection; nothing to do!') return else: if len(editor.getSelText()) == 0: if num_selections > 1: self.mb('No text in stream selections; nothing to do!') else: self.mb('No selected text; nothing to do!') return find_regex_str = self.remembered_find_regex_str repl_regex_str = self.remembered_repl_regex_str opt_case_sens = 'x' if self.remembered_case_sens_setting else ' ' opt_whole_word = 'x' if self.remembered_whole_word_setting else ' ' opt_regex = 'x' if self.remembered_regex_setting else ' ' opt_pre = 'x' if self.remembered_pre_repl_preview_setting else ' ' opt_post = 'x' if self.remembered_post_repl_summary_setting else ' ' input_stage = 'find' while True: # loop to validate user input if input_stage == 'find': user_reply_to_find_query = notepad.prompt( ' ' * 10 + 'Enter ? alone for help\r\nEnter FIND string:', self.script_name, find_regex_str) if user_reply_to_find_query == None: return # user cancel if len(user_reply_to_find_query) == 0: continue if user_reply_to_find_query == '?': self.mb(self.help_str) continue find_regex_str = user_reply_to_find_query input_stage = 'replace' if input_stage == 'replace': f = find_regex_str[:20] if f != find_regex_str: f += '...' user_reply_to_replace_query = notepad.prompt( ' ' * 5 + 'FIND string = {}\r\nEnter REPLACE string:'.format(f), self.script_name, repl_regex_str) if user_reply_to_replace_query == None: input_stage = 'find'; continue # go back to previous step if len(user_reply_to_replace_query) == 0: ync = self.mb('Replace matches with nothing, effectively deleting them?\r\n\r\n' 'YES = yes, delete matches\r\nNO = prompt again for what to replace with\r\n' 'CANCEL = go back a step (to prompt for find expression)', MESSAGEBOXFLAGS.YESNOCANCEL) if ync == MESSAGEBOXFLAGS.RESULTCANCEL: input_stage = 'find'; continue # go back to previous step elif ync == MESSAGEBOXFLAGS.RESULTNO: continue # repeat current step repl_regex_str = user_reply_to_replace_query input_stage = 'options' if input_stage == 'options': f = find_regex_str[:10] if f != find_regex_str: f += '...' r = repl_regex_str[:10] if r != repl_regex_str: r += '...' options_prompt = '[ {c} ]match-case ' + \ '[ {w} ]whole-word ' + \ '[ {re} ]regular-expression' + \ '\r\n' + \ '[ {pre} ]pre-replace-count-preview ' + \ '[ {post} ]post-replace-summary' options_prompt = options_prompt.format( c=opt_case_sens, w=opt_whole_word, re=opt_regex, pre=opt_pre, post=opt_post) user_reply_to_options_query = notepad.prompt( ' ' * 5 + \ 'FIND string = {} ' + \ 'REPLACE string = {}' + \ '\r\n' + \ 'Select OPTIONS: ' + \ 'Put any character inside the [ ] to select'.format( f, r if len(r) > 0 else 'NOTHING!'), self.script_name, options_prompt) if user_reply_to_options_query == None or len(user_reply_to_options_query) == 0: # go back to previous step input_stage = 'replace' continue if re.sub(r'\\[[^]]+\\]', r'[]', options_prompt) != \ re.sub(r'\\[[^]]+\\]', r'[]', user_reply_to_options_query): self.mb('Trouble parsing the options; please try again') continue options_str = user_reply_to_options_query def check_option(opt): # look in the [ ] boxes; return True if any non-space there m = re.search(r'\\[([^]]+)\\]' + opt, options_str) return True if m and m.group(1) != ' ' * len(m.group(1)) else False doing_case_sensitive = check_option('match-case') doing_whole_word = check_option('whole-word') doing_regex = check_option('regular-expression') doing_pre_replace_preview = check_option('pre-replace-count-preview') doing_post_replace_summary = check_option('post-replace-summary') self.remembered_find_regex_str = find_regex_str self.remembered_repl_regex_str = repl_regex_str self.remembered_case_sens_setting = doing_case_sensitive self.remembered_whole_word_setting = doing_whole_word self.remembered_regex_setting = doing_regex self.remembered_pre_repl_preview_setting = doing_pre_replace_preview self.remembered_post_repl_summary_setting = doing_post_replace_summary if doing_regex: try: editor.research(find_regex_str, lambda _: None) # test regex for validity except RuntimeError as r: self.mb('Error in search regular expression:\r\n\r\n' '{0}\r\n\r\n' '{1}\r\n\r\n\r\n' 'Click OK to try entering your find expression again'.format(find_regex_str, str(r))) input_stage = 'find' continue break total_number_of_matches = 0 if not doing_regex: find_regex_str = r'\Q' + find_regex_str + r'\E' # prevent problems with use of literal parenthesis characters in replace expression: repl_regex_str = re.sub(r'(?<!\\)([()])', r'\\\1', repl_regex_str) # replace parens with backslash-parens if doing_whole_word: find_regex_str = r'\b' + find_regex_str + r'\b' find_regex_str = '(?{}i)'.format('-' if doing_case_sensitive else '') + find_regex_str match_pos_span_tup_list = [] def match_found_func(m): match_pos_span_tup_list.append(m.span(0)) for n in range(editor.getSelections()): editor.research(find_regex_str, match_found_func, 0, editor.getSelectionNStart(n), editor.getSelectionNEnd(n)) total_number_of_matches = len(match_pos_span_tup_list) if total_number_of_matches == 0: self.mb('No matches found for :\r\n\r\n{}'.format(self.remembered_find_regex_str)) return if doing_pre_replace_preview: if self.mb('Make {tnom} replacement{s}?\r\n\r\n' 'Choose NO to not make the replacement{s} and see additional choices'.format( tnom=total_number_of_matches, s='s' if total_number_of_matches > 1 else ''), MESSAGEBOXFLAGS.YESNO) == MESSAGEBOXFLAGS.RESULTNO: if self.mb('End script and leave the {tnom} match{es} {ms}selected?\r\n\r\n' 'Choosing NO will end and leave the original search range selected'.format( tnom=total_number_of_matches, es='es' if total_number_of_matches > 1 else '', ms='multi-' if total_number_of_matches > 1 else ''), MESSAGEBOXFLAGS.YESNO) == MESSAGEBOXFLAGS.RESULTYES: first = True # get out of column selection mode as it messes up trying to correctly set selections later editor.setEmptySelection(match_pos_span_tup_list[0][0]) for (s, e) in match_pos_span_tup_list: editor.setSelection(e, s) if first else editor.addSelection(e, s) first = False return editor.beginUndoAction() self.custom_rereplace(find_regex_str, repl_regex_str) editor.endUndoAction() if not doing_pre_replace_preview and doing_post_replace_summary: self.mb('Replacements made: {}'.format(total_number_of_matches)) if __name__ == '__main__': try: rais except NameError: rais = RAIS() rais.run()
  • Need help please

    3
    0 Votes
    3 Posts
    250 Views
    Terry RT

    @wahlla-magla said in Need help please:

    I want to extract email:pass from every line to be like this

    @PeterJones had the right idea, it’s always difficult when not actually able to test a solution and in this case his will actually erase both user and email fields.
    Instead try
    Find What:(?-s)^.*?:(.+\R?)
    Replace With:\1

    As it’s a regular expression you must have the search mode set to regular expression.

    Terry

  • Cannot set as default app

    4
    0 Votes
    4 Posts
    314 Views
    PeterJonesP

    @roger-emmens said in Cannot set as default app:

    Any suggestions as to what to do?

    It shows up in my list as available for .txt (where it’s already chosen), but not on all others. Maybe because I had used an Windows Explorer > Right Click > Open With > Browse … or equivalent at one point, and/or because I’ve used the registry to manually associate with Notepad++, maybe then the default-app-by-file-type will show Notepad++ now.

    From what I can gather, with every update Windows is trying to make it harder and more annoying to use anything but “windows apps” from the Microsoft Store, so that (like Apple and Android) they can better track what their users are using, and control the experience. Notepad++ flirted with trying to do an official Microsoft Store release some time back, but the hoops they would have to jump through (and, IIRC, limitations that would have broken the existing plugin system) convinced Don that it wasn’t worth the hassle.

  • Two RTF presentations.

    4
    0 Votes
    4 Posts
    446 Views
    l'enfant diaboliqueL

    @artie-finkelstein

    Thanks for your advice, and in fact I’ll ask on an RTF forum.
    Thank you so much.

  • Adding linebreaks below characters

    14
    0 Votes
    14 Posts
    2k Views
    Alan KilbornA

    @kracovwolf said in Adding linebreaks below characters:

    so i should swap out the asterisks for <b> or style="font-weight: bold;?

    You should do that…if that is what you want to obtain.
    I think you can do a BIT of your own thinking here.

  • Global brace highlight style - disable for text files

    2
    0 Votes
    2 Posts
    231 Views
    PeterJonesP

    @erolb1 ,

    Short answer: no, there is no simple way to do that.

    Longer answer: and as far as I know, there is no complicated way to do that without editing the Notepad++ codebase.

  • How to format user defined language code?

    2
    0 Votes
    2 Posts
    1k Views
    PeterJonesP

    @moutaz-bakier ,

    User Defined Languages are just about syntax highlighting (adding color to keywords) – not about re-formatting your text for you.

    If I were trying to reformat a file with structure as simple as you’ve shown, I would just use a few search/replace pairs, all with Search Mode = Regular Expression enabled:

    FIND = ^\h*(?={|}|create)
    REPLACE = \t FIND = ^\h*(?=width|height|color)
    REPLACE = \t\t

    Those will change lines that start with any whitespace followed by { or } or create to start with a single tab; and lines that start with any whitespace followed by width or height or color into two tabs before the word. If, instead of tabs, you want 4 spaces or 8 spaces per tab, use four spaces or eight spaces in the first replace, and 8 or 16 spaces in the second replace.

    If the structure is the same, but there are more keywords that are always indented to a certain level, just add them as |keyword|another in the list of |-separated terms above. OTOH, if you actually have more complicated nesting with extra levels of { ... } or similar, and the ability for the same keywords to be at different levels depending on how deeply it’s nested, then the simplistic regex I supplied will not be enough.

    Many languages come with a “pretty print” or “tidy” utility, which allows you to pipe source code through that utility and it will come out with consistent formatting; using the NppExec plugin, you can pipe the active file through that re-formatting utility. @Michael-Vincent showns an example in this linked post of a script that will look at the file extension, and run it through one of many code reformatters, depending on language.

  • 0 Votes
    2 Posts
    304 Views
    guy038G

    Hello, @ruby-Pierce and All,

    First, I don’t know if you do use the simple double quote char " or if you need the opening and ending quotation marks ( the and chars with Unicode code-points \x{201C} and \x{201D} ), automatically provided by our NodeBB site !

    Anaway, here is a solution :

    Open the Replace dialog ( Ctrl + H )

    SEARCH ^{\R“identificationNumber” : “xxxx#######”,(?s).*?^},(\R|\z)     if couples of and are used

    OR

    SEARCH ^{\R"identificationNumber" : "xxxx#######",(?s).*?^},(\R|\z)     if the " char is only used

    REPLACE Leave EMPTY

    Tick the Wrap around option, preferably

    Select the Regular expression search mode

    Click on the Replace or Replace All buttons

    Of course, replace in the search regex, any x char by a letter and any # by a digit !

    Best Regards,

    guy038

  • Replacement does not abide Regular Expression

    5
    0 Votes
    5 Posts
    287 Views
    CsyeCokTheSollyC

    @alan-kilborn Thanks. That problem doesn’t occur now.

  • Line Number Display starting with 1

    3
    0 Votes
    3 Posts
    1k Views
    SS CheemaS

    @alan-kilborn Thank you! I was not aware of this plugin. I removed it.
    60e2eaec-fd36-46af-8f2a-08f3229196bc-image.png

  • Make Notepad++ dark (not editor theme, but editor itself)

    32
    7 Votes
    32 Posts
    32k Views
    Greg TurnerG

    @ahmed-syed I signed in to this site just to say THANK YOU!!! I did not know about the post-it mode and am absolutely loving it.
    I knew about adding virtual desktops but it’s good to see somebody else giving them some love. Most people I’ve interacted with just think it’s gimmicky, but if you know how to utilize it correctly, it can be an invaluable multi-tasking tool.

  • Is there an easy way to organize all of my NPP tabs?

    6
    0 Votes
    6 Posts
    7k Views
    Jason CoxJ

    @angrygamer Perfect! Thanks

  • Balloon popup with button hint?

    10
    0 Votes
    10 Posts
    655 Views
    Alan KilbornA

    @massimo-mula said in Balloon popup with button hint?:

    I also got NPP Portable from PortableApps.com, which is v. 1.8.9 too

    Do not do anything with portableapps.com, as that is not a recognized or supported provider of Notepad++. The official portable version of Notepad++ is on Notepad++'s own web site.

  • lexing/styling with PythonScript

    10
    1 Votes
    10 Posts
    937 Views
    Alan KilbornA

    @guy038 said in lexing/styling with PythonScript:

    …and, if your Python script support the (?-s) notation…

    So just a note on that comment:

    There are a couple of ways to use regular expressions in a PythonScript.

    One way is by using the PythonScript-specific functions, e.g. editor.research(). When you use this function, you are operating on editor data only(!) and you are using a Boost-compatible regular expression.

    The other way is to use Python’s (e.g.) re.search() function. This time, you are using Python’s own regex engine and you are acting on data that you specify, i.e., it cannot be data from the editor, directly. It can, of course be data that is copied from the editor into a Python variable.

    The second means described above is what my demo script above is using. Since Python’s regex flavor doesn’t accept (?-s) syntax, it isn’t possible to use it.

    Of course, the script could be reworked somewhat, in order to use the first method of data access, above, and then (?-s) would be available.

  • Conflict between user defined languages

    6
    0 Votes
    6 Posts
    513 Views
    John KollarJ

    I found the following issues posted on GitHub that look like they’re related to this discussion thread:

    UDL syntax highlighting and folding regions are completely broken. #10007
    https://github.com/notepad-plus-plus/notepad-plus-plus/issues/10007

    [UDL] “Force at beginning of line” for comments is buggy #9193
    https://github.com/notepad-plus-plus/notepad-plus-plus/issues/9193

    Notepad++ User-Defined Language syntax coloring occasionally mess up in 64-bit version #5156
    https://github.com/notepad-plus-plus/notepad-plus-plus/issues/5156

  • File Issue: cyrillic symbols in file displayed as '?'

    3
    0 Votes
    3 Posts
    421 Views
    artie-finkelsteinA

    @mike-carlove Any chance the menu selections in ‘the Encoding’ options have been changed?

  • print page number in footer

    3
    0 Votes
    3 Posts
    2k Views
    Alan KilbornA

    @jiri-cvrk

    Just an FYI: If you are looking to obtain “Page 3 of 7” I don’t think that is currently possible … the of 7 part.

  • Avoid reload popup when closing Notepad++

    6
    0 Votes
    6 Posts
    630 Views
    Francesco RombecchiF

    @neil-schipper Dear Neil,
    Hi Neil,
    I’ve tried turning off the automatic notification feature for changed files, I’ve also tried having it update without notification but it doesn’t do exactly what I want. Obviously my problem is just a nuisance, not a real error. If there is no solution, I will be fine with this walkaround.

    I’ll rewrite the situation that I’d like to see resolved:

    File Status Detection = enabled Update without notification = unchecked
    When I try to close a tab (or close Np++, or close all tabs) that has been updated by an external program Np++ asks me whether to reload the tab (and then closes it)
  • error in macros in Notepad++

    4
    1 Votes
    4 Posts
    876 Views
    EkopalypseE

    @heinz-berecz-0

    by installing the PythonScript plugin via PluginAdmin and using the notepad object with its menuCommand, runMenuCommand and runPluginCommand methods.
    Note that you can use the standard help function that Python normally has from within the PythonScript console window.
    For example: help(notepad.runMenuCommand)