F
F
Firefly872020-08-27 15:14:34
Regular Expressions
Firefly87, 2020-08-27 15:14:34

How to use regexp to select a character from a string at a given position (search and replace)?

Is it possible to use regular expressions to select a character at a given position in a string?

What interests me: There is a set of strings representing the date and time in the form YYYY-MM-DD-HH-MM-SS. You need to replace the '-' sign in the 11th position with a space.

My knowledge was only enough for such a regular expression: \^.{10}-\ and with groups: \^(.{10})(-)\

But the fragment gets into the result: 'YYYY-MM-DD-'. And I need the result to have only one character '-' which is located at the 11th position of the line. In the variant with groups, it would be possible to use the second group, but the program I work with does not understand the grouping and takes only both groups as a whole.

I cannot figure out how to exclude the first group from the selection or how to exclude the first 10 characters of the line from it. I searched on Google, but either I can’t formulate the question correctly or I was unlucky to find a solution.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
Timur Pokrovsky, 2020-08-27
@Firefly87

(?<=^.{10})-
https://regex101.com/r/XO2aRb/1

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question