Increment content found by regex and increment with other strings

Asked

Viewed 41 times

1

I need more help with regex, how do I find in a text a certain pattern and include something next to the string you found.
EX:

"programacao": "11h Abertura – Som Mecânico 12h30 Lino e Orquestra 15h30 Volkstanzgruppe Blauer Berg - Timbó - SC (Infanto Juvenil) 15h45.

Every time I meet the pattern xxhxx(12h30) for example, replaces with the same content and includes <br> being like this <br>12h30.

  • do you want to capture only the 12h30? or want to capture all hours and tag <br>?

  • I want to capture all hours and put <br>before, I’m using the sublime text, it does not recognize the $1

  • I edited the answer with the format that can be inserted in the sublime

  • by the way, +1 beautiful question

  • Thanks, +1 for the help there

1 answer

2


Answer
Use this regex p/ capture:

(\d{2}h\d{0,2})

In the replacement part use:

<br>\1

You can see how this regex works here.

Explanation

  • \d - identifies a number (0-9), equivalent to [0-9]
  • {2} - requires that it is necessary to find 2 digits in a row to give the match.
  • h - match with the character h
  • \d - identifies a number (0-9), equivalent to [0-9]
  • {0,2} - imposes that the previous pattern must be found between 0 and 2 times, after all the time can be represented as 12h = 12h00.
  • <br>\1 - in the replacement part you can use this pattern to insert <br>and what was captured in group 1 through the signal \

Browser other questions tagged

You are not signed in. Login or sign up in order to post.