donglv6960 2013-05-29 20:58
浏览 63
已采纳

RTLIT css padding rtl正则表达式

RTLIT ruby tool is used to switch from LTR to RTL in css files, but it doesn't also change the padding,margin left to righ for example :

https://github.com/zohararad/rtlit/blob/master/lib/rtlit/converter.rb

padding: 1px 2px;
padding: 0 2px 4px;
padding: 1px 0 3px 4px;
padding: 1px 2px 0 4px;
padding: 1px 2px 3px 0;

need to change this values to be :

padding: 1px 2px;
padding: 0 0 4px 2px;
padding: 1px 4px 3px 0;
padding: 1px 4px 0 2px;
padding: 1px 0 3px 2px;

we need to switch always the second value with the 4th value and if they are only 3 switch the second value to the forth and set the second to 0

also if there are only 2 values , leave it as it is.

I need that regular expression in ruby or php

  • 写回答

2条回答 默认 最新

  • dqh1992 2013-05-29 21:14
    关注

    try this in php:

    $result = preg_replace ('~\b(?:padding|margin)\b\h*:\h*\K(-?\d+[a-z%]*)\h+(-?\d+[a-z%]*)\h+(-?\d+[a-z%]*)\h+(-?\d+[a-z%]*)\h*(?=;)~i', '$1 $4 $3 $2', $string);
    

    with ruby:

    my_result = my_str.sub( %r{(?i)\b(padding|margin)\b *: *(-?\d+[a-z%]*) +(-?\d+[a-z%]*) +(-?\d+[a-z%]*) +(-?\d+[a-z%]*) *(?=;)}, '$1: $2 $5 $4 $3')
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 Jenkins+k8s部署slave节点offline
  • ¥15 微信小游戏反编译后,出现找不到分包的情况
  • ¥15 如何实现从tello无人机上获取实时传输的视频流,然后将获取的视频通过yolov5进行检测
  • ¥15 WPF使用Canvas绘制矢量图问题
  • ¥15 用三极管设计一个单管共射放大电路
  • ¥15 孟德尔随机化r语言运行问题
  • ¥15 pyinstaller编译的时候出现No module named 'imp'
  • ¥15 nirs_kit中打码怎么看(打码文件是csv格式)
  • ¥15 怎么把多于硬盘空间放到根目录下
  • ¥15 Matlab问题解答有两个问题