Small regular expression problems

Source: Internet
Author: User
String
$str = ' [Ol5febykjdwcdtrjzauf] 1 @ 2012-06-19 20:46:44 ';
I want to get
[] content within the []
] and the content between @
What's behind @
How to write a regular expression ...
School's all back to the teacher.


Reply to discussion (solution)

Print_r (Preg_split ('/[\[\]@]/', $str,-1, preg_split_no_empty));

Print_r (Preg_split ('/[\[\]@]/', $str,-1, preg_split_no_empty));



I now write Preg_match ("/\[(. *?)" \] (.*?) @ (\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2})/", $str, $m);
The result of the match is
$m =array ([0] = [Ol5febykjdwcdtrjzauf] 1 @ 2012-06-19 20:46:44 [1] = = Ol5febykjdwcdtrjzauf [2] = 1 [3] = 2 012-06-19 20:46:44)

How to modify the regular to get rid of the first item in the current result ($m [0])

You can use the Array_shift () function to delete the first element if you do not have the correct one.

You can use the Array_shift () function to delete the first element if you do not have the correct one.



Forget it, it's all a little problem, knot stickers.
  • 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.