Home>

Good afternoon!

There is a code:

@import url (<a  rel="nofollow noreferrer" href="http://fonts.googleapis.com/css?family=Bitter);">
http://fonts.googleapis.com/css?family=Bitter);
</a>@import "reset.css"; @ import "pro_pages_style.css"; @ import "grid.css"; @ import "forms.css"; @ import "prettyPhoto.css"; @ import "jquery.snippet.min.css ";
@import "../skin /blue.monday /jplayer.blue.monday.css"; @ import "../css /smoothness /jquery-ui-1.8.17.custom.css";
body {background: # 212d32; font: 14px /24px Georgia, "Times New Roman", Times, serif; color: # 7d919b; position: relative; min-width: 960px;}
html, body {height: 100%;}
p, .p {padding-bottom: 24px;}
.p0 {padding-bottom: 0! important;}
.p1 {padding-bottom: 10px;}
.p2 {padding-bottom: 15px;}
a {color: # 6ed3e5; outline: none; cursor: pointer; text-decoration: none;}
a: hover {text-decoration: underline}

I need to use regulars to pull all the style addresses into an array, such as grid.css, reset.css, etc.

I tried using code like this:

$ re= '/(t\"(.*)\";)/';
$ str= '@import url (<a  rel="nofollow noreferrer" href="http://fonts.googleapis.com/css?family=Bitter);%[email protected]">
http://fonts.googleapis.com/css?family=Bitter);\[email protected]"reset.css";@import"pro_pages_style.css";@import"grid.css";@import"forms.css " ; @import "prettyPhoto.css"; @ import "jquery.snippet.min.css"; \ n @ import "../skin /blue.monday /jplayer.blue.monday.css"; @ import "../css /smoothness /jquery-ui-1.8.17.custom.css "; \ nbody {background: # 212d32; font: 14px /24px
</a>Georgia, "Times New Roman", Times, serif; color: # 7d919b; position: relative; min-width: 960px;} \ nhtml, body {height: 100%;} \ np, .p {padding-bottom: 24px ;} \ n.p0 {padding-bottom: 0! important;} \ n.p1 {padding-bottom: 10px;} \ n.p2 {padding-bottom: 15px;} \ na {color: # 6ed3e5; outline: none; cursor: pointer; text-decoration: none;} \ na: hover {text-decoration: underline} ';
preg_match ($ re, $ str, $ matches);

But it doesn't work, please tell me.

[RESOLVED]

$ re= '/@import\"(.*)\";/U';
$ str= '@import url (<a  rel="nofollow noreferrer" href="http://fonts.googleapis.com/css?family=Bitter);%[email protected]">
http://fonts.googleapis.com/css?family=Bitter);\[email protected]"reset.css";@import"pro_pages_style.css";@import"grid.css";@import"forms.css " ; @import "prettyPhoto.css"; @ import "jquery.snippet.min.css"; \ n @ import "../skin /blue.monday /jplayer.blue.monday.css"; @ import "../css /smoothness /jquery-ui-1.8.17.custom.css "; \ nbody {background: # 212d32; font: 14px /24px
</a>Georgia, "Times New Roman", Times, serif; color: # 7d919b; position: relative; min-width: 960px;} \ nhtml, body {height: 100%;} \ np, .p {padding-bottom: 24px ;} \ n.p0 {padding-bottom: 0! important;} \ n.p1 {padding-bottom: 10px;} \ n.p2 {padding-bottom: 15px;} \ na {color: # 6ed3e5; outline: none; cursor: pointer; text-decoration: none;} \ na: hover {text-decoration: underline} ';
preg_match_all ($ re, $ str, $ matches);

What regulars have you tried? what didn't work?

zb'2021-02-23 00:20:13

Updated. Indicated what I tried.

chuikoff2021-02-23 00:20:13

Oh my God, why do you always parse everything with regular rules? Well they will help you a couple of times on the forum, but there will always be problems.

VladD2021-02-23 00:20:13

@chuikoff, you just need to properly design information processing systems. Design so that the question of parsing the code does not arise at all.

avp2021-02-23 00:20:13

@avp: I think TS parses CSS, and someone else's CSS. If you have your own CSS, of course, you should not be perverted with parsing, but receive data in normal form, as you wrote 4 hours ago.

VladD2021-02-23 00:20:13
  • Answer # 1

    Working example on http://ideone.com/LnZLGL
    Various intricacies of syntax are not taken into account, this was not the goal of the task.
    There is nothing difficult, he commented everything well:

    $ re= &lt;
    &lt;
    &lt;
    HEREDOC
        @import \\ s * # @import followed by whitespace
        (")? # quote, save to the first group
        (? (1) | # if the first group matches, then nothing is needed
             ((? &lt;
    = \\ s) url \\ s * \ () # ELSE brackets with url, save to the second group
        ) # end? (1)
        (? (1) | (? (2) | ^)) # fail a match if none of the two groups
                             # did not match
        (# third group to save the result
            (? (1) # if there was the first group
                [^ "] ++ | # THEN include all NOT quotes in the result
                [^ \)] ++ # ELSE include all NOT brackets
            ) # end? (1)
        ) # end of 3rd group
        # further two lines are fundamentally unnecessary -just for completeness of construction
        (? (1) # if there was the first group
             "| # THEN quotation mark
             \) # ELSE parenthesis
        ) # end? (1)
    HEREDOC;
    preg_match_all ("/$ re /sux", $ text, $ arr);
    var_dump ($ arr [3]);
    

    That's right, the whole problem was that I used preg_match instead of preg_match_all

    chuikoff2021-02-23 00:20:13

    What is the reason for this? preg_match_all (): Unknown modifier 'p' can't figure out where is this wrong modifier

    chuikoff2021-02-23 00:20:13

    You somewhere did not escape the slash followed by the character p

    ReinRaus2021-02-23 00:20:13

    @ReinRaus ♦ Right. There is also such a moment as to make sure that $ arr [3] does not have http: //, and must have .css to get rid of such constructions as @import url (fonts.googleapis.com/css?family=Bitter); which I don't need.

    chuikoff2021-02-23 00:20:13

    This is not relevant to the current question. Create a new one. In general, I stopped answering simple questions about regular expressions: They have no practical value, because there are no universal regular expressions -they are all sharpened for too narrow specific tasks. It was just that someone reopened the question after I closed it, and since the question was considered valuable, I gave the answer.

    ReinRaus2021-02-23 00:20:13