标签: preg-replace

preg_replace密码过滤器

使用PHP,我想对密码使用preg_replace()过滤器,以便密码可用的唯一字符是US ASCII typable,减去控制代码和NULL.

什么是RegEx来实现我可以插入preg_replace()的那个?

编辑:

我被建议编辑这个问题,因为我现在"得到它"并且不会做这种非常不受欢迎的技术并且允许任何可打字的字符,即使是我可能没有在键盘上的字符,只要它们不是控制代码.

php regex passwords filter preg-replace

10
推荐指数
2
解决办法
2370
查看次数

使用preg_replace时如何增加替换字符串中的计数?

我有这个代码:

$count = 0;    
preg_replace('/test/', 'test'. $count, $content,-1,$count);
Run Code Online (Sandbox Code Playgroud)

对于每次替换,我获得test0.

我想得到test0,test1,test2等.

php regex string preg-replace

10
推荐指数
2
解决办法
9840
查看次数

用preg_replace替换ereg_replace

您需要将功能更改ereg_replace("[\]", "", $theData)为preg_replace

php regex string preg-replace ereg-replace

10
推荐指数
1
解决办法
1万
查看次数

如何从字符串中删除单引号和双引号

当我通过此函数运行包含双引号的短语时,它用quot替换引号.

我想完全删除它们(也是单引号).我怎样才能改变这个功能呢?

function string_sanitize($s) {
    $result = preg_replace("/[^a-zA-Z0-9]+/", "", $s);
    return $result;
}
Run Code Online (Sandbox Code Playgroud)

更新:

Example 1: This is 'the' first example 
returns: Thisis030the039firstexample 
Errors: Warning: preg_match_all() [function.preg-match-all]: Unknown modifier '0' in C


Example 2: This is my "second" example
returns: Thisismyquotsecondquotexample
Errors: Invalid express in Xpath
Run Code Online (Sandbox Code Playgroud)

php preg-replace

10
推荐指数
2
解决办法
6万
查看次数

使用preg_replace()将CamelCase转换为snake_case

我现在有一个方法将我的驼峰案例字符串转换为蛇案例,但它分为三个调用preg_replace():

public function camelToUnderscore($string, $us = "-")
{
    // insert hyphen between any letter and the beginning of a numeric chain
    $string = preg_replace('/([a-z]+)([0-9]+)/i', '$1'.$us.'$2', $string);
    // insert hyphen between any lower-to-upper-case letter chain
    $string = preg_replace('/([a-z]+)([A-Z]+)/', '$1'.$us.'$2', $string);
    // insert hyphen between the end of a numeric chain and the beginning of an alpha chain
    $string = preg_replace('/([0-9]+)([a-z]+)/i', '$1'.$us.'$2', $string);

    // Lowercase
    $string = strtolower($string);

    return $string;
}
Run Code Online (Sandbox Code Playgroud)

我编写了测试来验证其准确性,并且它可以正常使用以下输入数组(array('input' => 'output')):

$test_values = [
    'foo' …
Run Code Online (Sandbox Code Playgroud)

php regex preg-replace

10
推荐指数
1
解决办法
1899
查看次数

9
推荐指数
2
解决办法
3021
查看次数

如何添加/到preg_replace模式

我做了这个简单的函数来过滤数据.我添加了允许包含的符号但我不知道如何添加/符号

public function filter($text)
  {
     return preg_replace('/[^^a-zA-Z0-9#@:_(),.!@" ]/','',$text);
  }
Run Code Online (Sandbox Code Playgroud)

php preg-replace

9
推荐指数
2
解决办法
2万
查看次数

替换模式内的所有实例

我有一个像这样的字符串

{{ some text @ other text @ and some other text }} @ this should not be replaced {{ but this should: @ }}
Run Code Online (Sandbox Code Playgroud)

我希望它成为

{{ some text ### other text ### and some other text }} @ this should not be replaced {{ but this should: ### }}
Run Code Online (Sandbox Code Playgroud)

我想这个例子很直接,而且我不确定我能更好地解释我想用文字实现的目标.

我尝试了几种不同的方法但没有效果.

php regex pcre preg-replace

9
推荐指数
1
解决办法
2万
查看次数

Python:preg_replace函数模拟

我在PHP中有一个litle表达式:

  $search = array("'<(script|noscript|style|noindex)[^>]*?>.*?</(script|noscript|style|noindex)>'si",
    "'<\!--.*?-->'si",
    "'<[\/\!]*?[^<>]*?>'si",
    "'([\r\n])[\s]+'");

$replace = array ("",
  "",
  " ", 
  "\\1 ");

  $text = preg_replace($search, $replace, $this->pageHtml);
Run Code Online (Sandbox Code Playgroud)

我是怎么在python上运行的?re.sub

php python preg-replace

9
推荐指数
1
解决办法
7216
查看次数

用元素替换每个字符

这就是我所拥有的

$str = 'Just a <span class="green">little</span> -text åäö width 123#';
Run Code Online (Sandbox Code Playgroud)

这就是我需要的

跨度和空间的结果也可能是换行符.

$result = '<span></span><span></span><span></span><span></span> <span></span> <span class="green"><span></span><span></span><span></span><span></span><span></span><span></span></span> <span></span><span></span><span></span><span></span><span></span> <span></span><span></span><span></span> <span></span><span></span><span></span><span></span><span></span> <span></span><span></span><span></span>';
Run Code Online (Sandbox Code Playgroud)

你可能想知道我可能需要这个.我想构建一个字符由块表示的东西.在Windows XP上看起来有点像Defrag.

  • <span></span>.替换每个角色.
  • 不要触摸字符串中已存在的HTML范围(可能很难?).可以有多个HTML元素.
  • 请勿触摸空格和换行符.
  • Regexp应该这样做吗?还是Xpath?

到目前为止我做了什么?

我找到了有关正则表达式但没有替换每个字符的文章(摘录空格和换行符)

$result = preg_replace("/???/", "<span></span>", $str);
print_r($result);
Run Code Online (Sandbox Code Playgroud)

php regex string replace preg-replace

9
推荐指数
1
解决办法
929
查看次数

标签 统计

php ×10

preg-replace ×10

regex ×7

string ×3

ereg-replace ×1

filter ×1

passwords ×1

pcre ×1

python ×1

replace ×1