Search code examples
regexreplacepspad

What is the regex to find a number followed by a period and replace the period


I am using PSPad and I am trying to replace the first period followed by a space with a pipe so I can use the pipe as a delimiter.

My data has lots of periods so I only want to replace the first one. The data looks like:

1. Wallbaum, H., S. Krank, 
3. Levinson, H.S., Highways, people,
4. Mercier, J., Equity, social justice, 
225. Lemp, J.D., et al., 
17. Chi, G. and B. Stone, 

Since the data always starts with a number followed by a period & space I figured the simplest thing to do was look for the number and space.

I have figured out the 'Find' part of the regex as ^\d+\. but how do I replace the period & space but leave the number?


Solution

  • Use capturing group as follow

    ^(\d+)\.\s
    

    and replace it with the first captured group $1 which will be the number.

    Regex Demo and Explanation

    1. ^: Starts with
    2. (\d+): Matches one or more digits and adds this in the first captured group
    3. \.: Matches dot literally, need to escape as it has special meaning in regex
    4. \s or (space): Matches one space. \s will also match any space characters like tabs.