Glam Prestige Journal

Bright entertainment trends with youth appeal.

I have this kind of html tag, which is interrupted by space at some point after word masuri:

<p>Aceasta este o melodie alcatuita din patru masuri:
reluata apoi de catre instrumentul solist cu un cintec popular.</p>

THE OUTPUT:

<p>Aceasta este o melodie alcatuita din patru masuri: reluata apoi de catre instrumentul solist cu un cintec popular.</p>

I want to replace the newline character in that particular tag <p></p>

I find an old regex made by @Toto, seems good, but doesn't make the replacement in order to get the output:

FIND: (?:<p>|\G)(?:(?!</p>).)*?\s\K\s+

REPLACE BY: (leave empty)

1

2 Answers

I simply make the assumption based on your desired output that you want to replace a newline character instead of a space.

This will match any single occurence of a newline inside of the specified tag:

(<p>)+(.)+\K(\r\n|\r|\n)(?=.*<\/p>)

Explanation:

(<p>)+(.) matches the opening tag + any character that follows

\K resets the matches

(\r\n|\r|\n) matches the newline character

(?=.*<\/p>) checks for any character +

after the match 4

So, the regex that removes newsline is (?<=[^\r\n])\R(?=[^\r\n]). I put this regex in this new regex formula, at the end. See also below the source of how I manage to resolve the problem.

Use the following:

  • Ctrl+H
  • Find: (?-i:<p>|(?!\A)\G)(?s:(?!</p>).)*?\K(?-i:(?<=[^\r\n])\R(?=[^\r\n]))
  • Replace with: \x20
  • CHECK Match case
  • CHECK Wrap around
  • CHECK Regular expression
  • UNCHECK . matches newline
  • Replace all

I resolve this problem by reading this topic:

I fully endorse your new abbreviations ! So :

Let FR (Find Regex ) be the regex which defines the char, string or expression to be searched
Let RR (Replacement Regex ) be the regex which defines the char, string or expression which must replace the FR expression
Let BSR ( Begin Search-region Regex ) be the regex which defines the beginning of the area where the search for FR, must start
Let ESR ( End Search-region Regex) be the regex which defines, implicitly, the area where the search for FR, must end

Then, the generic regex can be expressed :

SEARCH: (?-i:BSR|(?!\A)\G)(?s:(?!ESR).)*?\K(?-i:FR)

REPLACE: RR

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy