I want to replace all the src attributes with data-src in the <img> tags, throughout the project, but so that the script, js-code, etc. tags are not affected. Although I now thought that the search for 'src = "' would only affect <script> tags with src and then, in principle, it’s not difficult to change manually. Is it possible to do this with a regular expression? I looked for examples, but they didn’t fit

    1 answer 1

    PHP example

     $string = '<img title="xd" src="test">'; // примерная строка echo preg_replace('/img.*\K(src)/ui', 'data-src', $string); 

    Conclusion:

    <img title="xd" data-src="test">

    • it will not work, but perhaps it will help someone - Eugen Gedroyc
    • @EugenGedroyc, and in which program you want to replace? - user273447
    • in one of them: Notepad ++, brackets, Atom - Eugen Gedroyc
    • @EugenGedroyc, replaced just in Sublime Text and in Notepad ++, everything works fine, describe your problem, what is not suitable? - user273447
    • 2
      @EugenGedroyc, why do you replace the regular season with the regular season? imageup.ru/img48/3084136/bezymyannyjj.png - user273447