-1

I have a scenario where I have list with some numbers in Notepad++. Here is the sample text:

1-This is item one
2_This is item two
3This is item three
4_This is item five
5This is item six
6 This is item seven

I want to put an underscore after the numbers so the output is like:

1_This is item one
2_This is item two
3_This is item three
4_This is item five
5_This is item six
6_This is item seven

Here is the code which I have written (\d+)(?!_).(.+?) and replace \1_\2

It is deleting the first character of point 3 and 5, "T" in this case.

6
  • grep is only used to find, not to replace. Please, review your tags. I guess you are talking about Adobe-Indesing, aren't you? What are “n-space” and “m-space”?
    – Toto
    Commented Jul 1 at 18:00
  • Yes you are right. I use grep mostly in Adobe's InDesign. Sometimes, I copy paste the data in Notepad++, use regex and the copy back to InDesign. In InDesign n-space's width is lesser than m-space's width. If I talk specifically about n-space, in InDesign it is denoted by ~> (unicode \u2002). For m-space unicode is \u2003. \h matches all the spaces, be it n or m or thin or normal space. In Indesign replace is like substitution in Notepad++ or regex101.
    – Shahid
    Commented Jul 1 at 18:12
  • How about: Find: (\x{602}\d+)(?!~>)\h*(?=[Range of characters you want]) and Replace: $1~> ?
    – Toto
    Commented Jul 1 at 19:17
  • Please, don't put example in comments (it could be deleted!), edit your question and add sample text (not an image) and expected result. I don't understand why you're talking about spaces in the question and, now, you have hyphens and underscores.
    – Toto
    Commented Jul 2 at 15:45
  • Actually n-spaces and m-spaces are not available in other programs so I put and English example with dashes and underscore.
    – Shahid
    Commented Jul 2 at 16:07

1 Answer 1

3
  • Ctrl+H
  • Find what: \d+\K[^a-z]*
  • Replace with: _
  • UNTICK Match case
  • TICK Wrap around
  • SELECT Regular expression
  • Replace all

Explanation:

\d+         # 1 or more digits
\K          # forget them
[^a-z]*     # 0 or more any character that is not a letter

Screenshot (before):

enter image description here

Screenshot (after):

enter image description here

2
  • It worked like a charm.
    – Shahid
    Commented Jul 2 at 16:21
  • @Shahid: You're welcome, glad it helps.
    – Toto
    Commented Jul 2 at 16:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .