Ask a regular replacement question

Source: Internet
Author: User
There are strings such as:

Get_post_title

Find_my_article


Such a string, how to replace it with regular: Getposttitle,findmyarticle?

With Explode,array_map (Ucword), such a way has been used. Now want to use the regular to achieve, but not enough skill


How do you spell the regular?


Reply to discussion (solution)

$s = ' get_post_title '; echo preg_replace ('/(^|_) (\w)/E ', ' Strtoupper ("$") ', $s);

$s = ' get_post_title '; echo preg_replace ('/(^|_) (\w)/E ', ' Strtoupper ("$") ', $s);


Thank you, owner. Can you tell me about this regular-style analytical idea?

If this is the string: A,b,c,d becomes ' a ', ' B ', ' C ', ' d '? How do you spell the regular?

This is good, the E attribute is listed in the abolition of the list

$s = ' a,b,c,d '; echo preg_replace_callback ('/(?: ^|,) ([A-z])/', function ($r) {return "' $r [1] '";}, $s);

Thank you. But when I was using JavaScript to do this, it seemed a bit wrong. Please take a little solution.

"Get_post_title". Replace (/(^|_) (\w)/g,function ($) {return $2.touppercase ();}) Returns the result: Get_post_title


Don't know why

This is good, the E attribute is listed in the abolition of the list

$s = ' a,b,c,d '; echo preg_replace_callback ('/(?: ^|,) ([A-z])/', function ($r) {return "' $r [1] '";}, $s);


The result of the operation is not quite right.
I wrote it myself:
$s = ' a,b,c,d '; echo preg_replace_callback ('/(\w)/', function ($r) {return "' $r [1] '";}, $s);
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.